How do i create relationships for existing nodes b

2019-08-06 19:41发布

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条回答
虎瘦雄心在
2楼-- · 2019-08-06 20:00

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

查看更多
登录 后发表回答