简体   繁体   中英

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

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
....

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM