Import data from 2 csv files in neo4j

烂漫一生 提交于 2020-04-17 21:28:30

问题


As a continue to this post in which I completely explained what I'm supposed to do, in case my central node is located in another .csv file, how can I import it in my graph?

The content of names.csv (2 columns: Lname & Fname):

Lname,Fname
Brown,Helen
Right,Eliza
Green,Helen
Pink,Kate
Yellow,Helen

The content of central.csv (2 columns: central & value):

central,value
cent1,10

I tried something like this:

LOAD CSV WITH HEADERS FROM 'file:///central.csv' AS frow
MERGE (c:center {name: frow.central})
WITH *
LOAD CSV WITH HEADERS FROM 'file:///names.csv' AS srow
WITH srow.Fname AS first, srow.Lname AS last
MERGE (p:la {last: last})
MERGE (o:fi {first: first})
MERGE (c)-[r:CONTAINS {first:first}]->(o)
MERGE (o)-[rel:CONTAINS {first: first}]->(p)
RETURN count(o)

but it didn't work for me. It created the central node for me, but my central node is not connected to first nodes as it was supposed to. What's wrong. I wanted it to be like this:


回答1:


Your second WITH clause does not contain c, so c becomes an unbound variable after that clause.

Change this:

WITH srow.Fname AS first, srow.Lname AS last

to this:

WITH c, srow.Fname AS first, srow.Lname AS last

By the way, your query will only work as you expect if central.csv contains just one data row (as it does currently).



来源:https://stackoverflow.com/questions/60288663/import-data-from-2-csv-files-in-neo4j

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!