Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.
09-28-2022 10:54 AM
Good evening, I'm new to the comunity, I would like to import the diagram below into neo4j
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.
Solved! Go to Solution.
10-01-2022 11:33 AM
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)
09-28-2022 11:13 AM
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.
09-28-2022 11:17 AM - edited 09-28-2022 11:19 AM
09-28-2022 11:23 AM
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?
09-28-2022 01:12 PM
What is the issue you need help with.
09-29-2022 06:42 AM
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?
09-29-2022 12:15 PM
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/
10-01-2022 08:58 AM
I tried with etl and partly solved the problem, can I attach the three files in question in the post?
10-01-2022 09:33 AM
Sure.
10-01-2022 11:03 AM
10-01-2022 11:33 AM
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)
10-01-2022 11:37 AM
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
10-02-2022 01:59 AM
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!
10-02-2022 04:55 AM
Sorry. You need to insert ‘:auto’ at the beginning of the query.
10-02-2022 01:53 AM
thank you very much, it works at the moment, I should test it!
All the sessions of the conference are now available online