Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.
08-21-2020 08:44 AM
The result should look like this
What Cyper-query should I use?
08-21-2020 09:28 AM
I believe this APOC procedure you're looking for https://neo4j-contrib.github.io/neo4j-apoc-procedures/3.5/graph-refactoring/merge-nodes/.
09-06-2020 10:45 AM
I have been applying APOC Merge with this Query:
MATCH (m:YellowNode) WHERE m.name = 'This' AND m.range = [0,4] WITH collect(m) AS marks CALL apoc.refactor.mergeNodes(marks, {{ properties:'override', mergeRels: false}}) YIELD node RETURN node.creationTime, node.name, ID(node), labels(node)
As you can see it removes the relations called Spec as part of the merge. What happens here?
09-09-2020 02:36 AM
I'm not totally sure but it looks like it's not capturing those nodes in the pattern you're trying to merge. You're also passing merge relationships as false which may be excluding them from being passed correctly to your yellow node.
09-09-2020 04:38 PM
Try this:
MATCH (a:Red)
MATCH (a)-[:Mark]->(c:Yellow)
WITH a, collect(c) as subgraph
CALL apoc.nodes.collapse(subgraph,{properties:'combine', collapsedLabel: true})
YIELD from, rel, to
WITH a, from , rel, to where labels(to) in [['Green']]
//Following RETURN gives you the virtual collapsed node....
//RETURN from , rel, to
// See fig. below.....
//Create a real node same as virtual node.....
WITH a, from , rel, to, collect(to) as t1
UNWIND t1 as t12
MERGE (g:Collapsed{name: "This"})
MERGE (g)-[:Spec]->(t12)
MERGE (a)-[:Mark]->(g)
// This returns the merged node...
RETURN from, rel, to, g, a
//See Fig. below
//Now cleaning up the yellow nodes......
MATCH (a:Red)-[r:Mark]->(b:Yellow)
DELETE r
DETACH DELETE b
//Final result...
MATCH (n) RETURN n
Fig. below
Instead of deleting yellow nodes, you can keep them and show the collapsed or the expanded version.
All the sessions of the conference are now available online