How do i create relationships for existing nodes by importing csv file in neo4j?

﹥>﹥吖頭↗ 提交于 2019-12-11 07:09:22

问题


lets say i have created [a],[b],[c],[d] nodes in neo4j. how to create relationships among those nodes by importing csv data.

csv data:

id,fromNode,toNode,typeOfRelation
1,a,b,KNOWs
2,b,c,FOLLOWS
3,d,a,KNOWS
....

回答1:


I would do it like this way if your Nodes are in the Graph already.

CREATE INDEX ON :Label(name);

LOAD CSV WITH HEADERS FROM "file:///<PathToYourCSV>" as input
MATCH (from:Label  {name: input.fromNode}), (to:Label {name: input.toNode})
CREATE (from)-[:RELATION { type: input.typeOfRelation }]->(to);

To query it, you can use

MATCH (n:Label {name: 'b'}), 
(n)-[rel:RELATION]->(follower)
where rel.type = 'FOLLOWS'
return n, follower

Patrick



来源:https://stackoverflow.com/questions/26279278/how-do-i-create-relationships-for-existing-nodes-by-importing-csv-file-in-neo4j

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