Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.
11-24-2021 11:50 PM
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)
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
11-26-2021 01:12 AM
Hi Yejin,
Did you managed to solve the issue?
Cheers,
Dominic
12-02-2021 01:39 AM
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)
12-13-2021 11:44 PM
Thanks, we solved the problem in other way but thank you for replying.
I will try your query later!
Cheers,
03-13-2022 04:16 AM
Hi Yejin, I happened to face the same issue, do you mind to share how you solved it? thankyou
All the sessions of the conference are now available online