cancel
Showing results for 
Search instead for 
Did you mean: 

Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.

NotFoundException error for using Merge Nodes Apoc

jin_what
Node Link

Hi guys,

I was trying to merge some node groups into one node based on their label.
I looked at neo4j documentation (Merge Nodes - APOC Documentation) and tried to apply the query with my cases but it came up with this error.

1)


This is the graph I am working on and I set different colors to nodes based on thier labels.
What I am trying to do is to match the path which is consisted of nodes with same labels and merge them into one node for better visualization.

2)

MATCH (a:Stop)-[:HUWON]->(b:Stop)
WITH [a,b] as nodes
CALL apoc.refactor.mergeNodes(nodes,{properties:"combine", mergeRels:TRUE, produceSelfRel:FALSE})
YIELD node
RETURN count(*);

I wanted to merge nodes by matching specific paths(consisted of only ( :Stop) and [ :HUWON]) and enlist them but it show this certain errors.

I am not sure how this Apoc works but I can't just use
WITH Head(collect([a1,a2])) as nodes like an example from documentation because
then it will only merge the first path in the list due to head().

Can you help me with this? @dominic.teo

Thanks in advance!

Yejin

4 REPLIES 4

Hi Yejin,

Did you managed to solve the issue?

Cheers,
Dominic

@jin_what

I think the problem is this one: https://github.com/neo4j-contrib/neo4j-apoc-procedures/issues/578#issuecomment-364105387


That is, is a Cypher behaviour that cannot be fixed with apoc itself.

So, a workaround is putting WITH * LIMIT 1 after the MATCH clause.
Of course, will be merged only 1 result at once.


Or even better, you could put the query into a apoc.periodic.repeat,
so that you can execute the query every second and, instead of a match between 2 nodes, execute a match between multiple nodes (a:Stop)-[:HUWON*]->(b:Stop) ad pick the longest path, to execute fewer executions. That is:

call apoc.periodic.repeat("merge", 'MATCH p=(a:Stop)-[:HUWON*]->(b:Stop) 
WITH p, length(p) AS length ORDER BY length DESC LIMIT 1 CALL apoc.refactor.mergeNodes(nodes(p),{properties:"combine", mergeRels:TRUE, produceSelfRel:FALSE})
YIELD node RETURN count(*)', 1)

Anyway, with big databases, the `ORDER BY length` could be heavy, so you could do only `MATCH p=(a:Stop)-[:HUWON*]->(b:Stop) WITH p LIMIT 1` after `CALL mergeNodes`.

Thanks, we solved the problem in other way but thank you for replying.
I will try your query later!

Cheers,

Hi Yejin, I happened to face the same issue, do you mind to share how you solved it? thankyou