Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.
03-28-2022 07:13 AM
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:
https://git.thm.de/aksz15/download/-/raw/master/export.cypher
03-28-2022 10:13 AM
Is it possible for your data to have the same node related to more than one node, so that the time it is trying to merge it for the second time, it has been already merged and does not exists.
03-28-2022 10:21 AM
Could be ... haven't thought about that possibility yet.
03-28-2022 10:29 AM
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].
03-28-2022 10:33 AM
Yes, but how can i organize this ...
03-28-2022 10:40 AM
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.
match(n1:Person)
match(n2:Person)
match(n1)-[r1:SAME_AS]->(n2)
match(n2)-[r2:SAME_AS]->(n1)
delete r2
03-28-2022 10:45 AM
I found 78 relationships, 8 being bidirectional. After the delete, there are 70 relationships and I did not see any bi-directional pairs in the graph.
03-28-2022 12:58 PM
Thats the point - thank you 😉
03-28-2022 01:38 PM
Did that solve your problem?
03-30-2022 02:05 AM
Unfortunately not because the bigger picture is more complicated. But your notes made the problems clear for me and I'm working on it.
All the sessions of the conference are now available online