cancel
Showing results for 
Search instead for 
Did you mean: 

Join the community at Nodes 2022, our free virtual event on November 16 - 17.

apoc.refactor.mergeNodes`: Caused by: org.neo4j.graphdb.NotFoundException: Node 912779 not found

andreas_kuczera
Graph Buddy

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

9 REPLIES 9

glilienfield
Ninja
Ninja

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.

Could be ... haven't thought about that possibility yet.

glilienfield
Ninja
Ninja

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].

Yes, but how can i organize this ...

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

glilienfield
Ninja
Ninja

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.

Thats the point - thank you 😉

Did that solve your problem?

andreas_kuczera
Graph Buddy

Unfortunately not because the bigger picture is more complicated. But your notes made the problems clear for me and I'm working on it.

Nodes 2022
Nodes
NODES 2022, Neo4j Online Education Summit - November 16 - 17, 2022.


Free NODES Training Series


October 19th -

Intro to Neo4j


October 20th -

Healthcare Analytics Using Neo4j


October 25th -

Handling Neo4j data with Apache Hop


October 26th -

Blazing Fast Graphs: Hands-on with Apache Arrow and Neo4j


November 2nd -

Graph EDA Using the Neo4j GDS Client