如何通过在neo4j中导入csv文件来为现有节点创建关系? [英] How do i create relationships for existing nodes by importing csv file in neo4j?
本文介绍了如何通过在neo4j中导入csv文件来为现有节点创建关系?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
csv data:
id,fromNode,toNode,typeOfRelation
1,a,b,KNOWs
2,b,c,FOLLOWS
3,d,a,KNOWS
....
解决方案
如果您的节点已经在图形中,我会这样做.
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);
要查询,可以使用
MATCH (n:Label {name: 'b'}),
(n)-[rel:RELATION]->(follower)
where rel.type = 'FOLLOWS'
return n, follower
帕特里克
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
这篇关于如何通过在neo4j中导入csv文件来为现有节点创建关系?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文