In a database with genealogical informations i try to merge nodes of persons which belong to the same person. They are connected with "SAME_AS" edges. When i try this query:
MATCH (n1:Person)-[s1:SAME_AS]-(n2:Person) WHERE n1.properties =~ '[A-Z][1-9].*' AND n1.age = n2.age WITH collect([n2, n1]) as listOfNodes LIMIT 100000 UNWIND listOfNodes as nodes call apoc.refactor.mergeNodes(nodes) yield node return count(*); return nodes;
I get this error message:
Neo.ClientError.Procedure.ProcedureCallFailed: Failed to invoke procedure `apoc.refactor.mergeNodes`: Caused by: org.neo4j.graphdb.NotFoundException: Node 912779 not found
Here is the code to create the test graph:
I see in your data you have a few pair of nodes that have a bi-directional SAME_AS relationship, so you would have elements [n1, n2] and [n2, n1] in your listOfNodes. I would imagine after the first element [n1, n2] gets merged, then you would get the node-not-found error when merging [n2, n1].
You can delete one of the bidirectional relationships before your merge query. The following should find the pairs that have bi-directional relationships and delete one of them. The query found 8 of them.