2

I need to collapse two nodes to a one node. I have gone this far "below" but I could not achieve what i want.

For example I want to collapse "guy" node and "love" node to a new node preserving the path.

practitioner
  • 412
  • 1
  • 5
  • 12

2 Answers2

0

There is a procedure in APOC for that : apoc.refactor.mergeNodes

Example :

MATCH (f:Node {value:'Guy'}), (b:Node {value:'Love'})
WITH * LIMIT 1
CALL apoc.refactor.mergeNodes([f,b])
YIELD node RETURN node
logisima
  • 7,340
  • 1
  • 18
  • 31
  • Thanks for mentioning APOC. I tried to do it but got this error: ConstraintError: org.neo4j.kernel.api.exceptions.ConstraintViolationTransactionFailureException: Cannot delete node<81>, because it still has relationships. To delete this node, you must first delete its relationships. – practitioner Apr 23 '18 at 15:20
  • It seems that there is bug on this feature : https://github.com/neo4j-contrib/neo4j-apoc-procedures/issues/578. I have updated my response with the mentioned work-around on the issue – logisima Apr 23 '18 at 15:28
  • is there a way to update the properties of the new merged node? (while merging) – practitioner Apr 23 '18 at 16:21
  • yes see the documentation -> https://neo4j-contrib.github.io/neo4j-apoc-procedures/#_merging_nodes – logisima Apr 23 '18 at 18:57
-1

Try creating a new node with the properties you desire and then remove the nodes(guy and love) by using DETACH DELETE.

techie95
  • 515
  • 3
  • 16