如何在neo4j的现有节点中附加关系?

时间:2016-05-21 13:58:53

标签: graph neo4j cypher relationship

我正在尝试从csv文件制作图表,但我无法在现有节点中添加其他关系。

我的实际代码是:

USING PERIODIC COMMIT 10000
LOAD CSV FROM 'my_file.csv' AS line
MERGE (p:Title { title: line[0]})

MERGE (a:Author { name: line[1]})
MERGE (a)-[:COLABORATE_IN]->(p)

WITH line  WHERE line[2] IS NOT NULL
MERGE (b:Author {name: line[2]})
MERGE (b)-[:COLABORATE_IN]->(p) //not working 

RETURN line[2]

它应该很简单,它可以很好地创建节点和第一关系,但对于第[2]行,它只是为新节点创建关系。我能做什么?

由于

1 个答案:

答案 0 :(得分:1)

MERGE (a:Author { name: line[1]}) MERGE (a)-[:COLABORATE_IN]->(p) WITH line WHERE line[2] IS NOT NULL // p is no more available here 子句中未通过管道传输的所有内容都无法用于查询的下一部分:

p

只需添加USING PERIODIC COMMIT 10000 LOAD CSV FROM 'my_file.csv' AS line MERGE (p:Title { title: line[0]}) MERGE (a:Author { name: line[1]}) MERGE (a)-[:COLABORATE_IN]->(p) WITH p, line WHERE line[2] IS NOT NULL MERGE (b:Author {name: line[2]}) MERGE (b)-[:COLABORATE_IN]->(p) //not working RETURN line[2] 标识符,即可在查询的其余部分中使用该标识符:

BufferedReader