cancel
Showing results for 
Search instead for 
Did you mean: 

import problems in neo4j

spiaggia06
Node

Good evening, I'm new to the comunity, I would like to import the diagram below into neo4j

schema_workbanch.png

there is an easy way, i tried apoc and etl but i am stuck to relations (apoc) and etl only imports two tables (regions and provinces). there is an automated way. I'm new to the system. 

1 ACCEPTED SOLUTION

Try this...it was based on my understanding of the data. We can fix it if it doesn't meet your model expectations.

I separated the import into three parts. Run the region and providence import scripts first. The last one links them together, so they must exists already.  

load csv with headers from "file:///Regione.csv" as row
merge(n:Regione{id: row.id_regione})
set n.sigla_regione = row.sigla_regione, n.nome_regione = row.nome_regione
load csv with headers from "file:///provincia.csv" as row
merge(n:Provincia {id: row.id_provincia})
set n.provincia = row.provincia, n.sigla = row.sigla
load csv with headers from "file:///comune.csv" as row
match(p:Provincia{id: row.id_provincia})
match(r:Regione{id: row.id_regione})
merge(c:Comune{id: row.id})
set c.istat = row.istat, c.prefisso = row.prefisso, c.cap = row.cap, c.codfisco = row.codfisco, c.link = row.link
merge(c)-[:HAS_REGIONE]->(r)
merge(c)-[:HAS_PROVINCIA]->(p)

 

View solution in original post

14 REPLIES 14

glilienfield
Ninja
Ninja

do you have the data from each table in separate spreadsheets with primary and foreign keys. If so, you probably can use the data importer tool. 

https://graphacademy.neo4j.com/courses/importing-data/

you can also write your own scripts. Can you share what you have done already and what is missing. 

kasipasi
Node Clone
I'm also a beginner. 🙂
 
These are the two script I have been able to load almost 50k lines with:
 
Loading first a eclass structure:
 
USING PERIODIC COMMIT
LOAD CSV WITH HEADERS FROM 'file:///eclass12-EN.csv' AS row
MERGE (e:Eclass { standard: row.Standard, versionNumber: row.VersionNumber, isoLanguageCode: row.ISOLanguageCode, codedName: row.CodedName, idcc:row.IdCC, preferredName: row.PreferredName, definition: COALESCE(row.Definition, ''), mkKeyword: COALESCE(row.MKKeyword, ''), irdicc: row.IrdiCC });
 
After relates eclass code with each part:
 
USING PERIODIC COMMIT
LOAD CSV WITH HEADERS FROM 'file:///partsupply.csv' AS row
WITH row
MATCH (e:Eclass {codedName: row.ECLASS})
MERGE (p:Product { partName: row['Part Name'], partNumber: COALESCE(row['Part Number'], ''), supplier: row.Supplier, eclass: row.ECLASS, picture_url: row['Picture URL'] })
MERGE (p)-[r:belongs_to]->(e);

What specifically is wrong with the results you get? 

Is the data from the three tables merged into one file, as your query is just one file. 

Do you have a data model you want to create? 

What is the issue you need help with. 

the problem is that I can't import the data. I would like to understand whether to import single table in csv or complete table? Do relationships need to be created by hand or do I need to run additional scripts?

I would import one of the tables at a time. If you are writing your own import cypher, you will need to create the nodes and the relationships yourself. There is nothing automatic. It looks like you got this concept understood based on the code you pasted. 

You will need your csv files to include the equivalent to of primary and foreign keys, so you can link the entries with a relationship. I can help if you provide snippets of the data from each file.

this may help: https://neo4j.com/developer/guide-importing-data-and-etl/

spiaggia06
Node

I tried with etl and partly solved the problem, can I attach the three files in question in the post?

Sure.

I loaded the three tables already populated, I could not realize the reports. the scheme er is above.

Try this...it was based on my understanding of the data. We can fix it if it doesn't meet your model expectations.

I separated the import into three parts. Run the region and providence import scripts first. The last one links them together, so they must exists already.  

load csv with headers from "file:///Regione.csv" as row
merge(n:Regione{id: row.id_regione})
set n.sigla_regione = row.sigla_regione, n.nome_regione = row.nome_regione
load csv with headers from "file:///provincia.csv" as row
merge(n:Provincia {id: row.id_provincia})
set n.provincia = row.provincia, n.sigla = row.sigla
load csv with headers from "file:///comune.csv" as row
match(p:Provincia{id: row.id_provincia})
match(r:Regione{id: row.id_regione})
merge(c:Comune{id: row.id})
set c.istat = row.istat, c.prefisso = row.prefisso, c.cap = row.cap, c.codfisco = row.codfisco, c.link = row.link
merge(c)-[:HAS_REGIONE]->(r)
merge(c)-[:HAS_PROVINCIA]->(p)

 

BTY, this data seems completely different from the data you were importing in your posted scripts.  Anyway, it shows you the general approach to importing data.

Do you have a lot of data that would justify splitting the import into multiple transactions. If so, you can use the call subquery with transactions as such:

load csv with headers from "file:///Regione.csv" as row
call {
with row
merge(n:Regione{id: row.id_regione})
set n.sigla_regione = row.sigla_regione, n.nome_regione = row.nome_regione
} in transactions of 1000 rows

A query with 'CALL { ... } IN TRANSACTIONS' can only be executed in an implicit transaction, but tried to execute in an explicit transaction.

the error I generated! 

Sorry. You need to insert ‘:auto’ at the beginning of the query. 

thank you very much, it works at the moment, I should test it!