从csv文件中创建neo4j中节点之间的动态关系

时间:2017-05-25 16:23:07

标签: neo4j cypher

您有一个CSV文件,我想同时创建节点和关系    我使用以下查询来创建节点

using PERIODIC COMMIT 1000
load csv from "file:///home/gaurav/sharing/dataframe6.txt" as line fieldterminator" "
 MERGE (A :concept{name:line[0]})
 WITH line, A
 MERGE (B :concept{name:line[1]})
 WITH line, A, B
 create (A)-[:line[3]]->(B);  // This is trouble part

但是当我尝试在导入的节点之间创建关系时,我得到错误

Invalid input '[': expected an identifier character, whitespace, '|', a length specification, a property map or ']' (line 7, column 18 (offset: 218))
"create (A)-[:line[3]]->(B);"

2 个答案:

答案 0 :(得分:3)

如果您真的想以动态方式创建关系,则需要使用APOC程序,特别是apoc.create.relationship

using PERIODIC COMMIT 1000
load csv from "file:///home/gaurav/sharing/dataframe6.txt" as line fieldterminator" "
MERGE (A :concept{name:line[0]})
WITH line, A
MERGE (B :concept{name:line[1]})
WITH line, A, B
CALL apoc.create.relationship(A, line[3], {}, B) YIELD rel
RETURN A,B,rel

答案 1 :(得分:0)

关系不能包含方括号作为其类型名称。您正试图在节点A和B之间创建“line [3]”关系。