neo4j apoc merge nodes to one specific node

时间:2018-02-03 09:38:55

标签: neo4j cypher

In our graph we have some nodes of persons which are connected with SAME_AS-edges, because they all mean the same person.

enter image description here

enter image description here

One of the nodes, with the name-property starting with a major character and a number is the main node, to which all others should be merges to.

Any help would be great.

1 个答案:

答案 0 :(得分:0)

就像杰罗姆所说的那样,你应该使用APOC来执行apoc.refactor.mergeNodes程序。

但如果出现以下情况,您可能会遇到错误:

  • 您的节点未使用索引
  • 查找
  • 或者,如果您在调用程序之前没有在执行计划中有一个急切的阶段(针对您的节点)。

所以要解决这个问题,你可以这样做:

MATCH (n1:Person {name:$name1}),
      (n2:Person {name:$name2}),
      (n3:Person {name:$name3}),
      (n4:Person {name:$name4})
WITH head( collect( [n1, n2, n3, n4] ) ) AS nodes
  CALL apoc.refactor.mergeNodes(nodes)  YIELD node 
  RETURN node