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