cancel
Showing results for 
Search instead for 
Did you mean: 

MERGE duplicate relationships

VilladsClaes
Node Clone

This CYPHER

MATCH(a) WHERE ID(a) =1 MATCH(b) WHERE ID(b) = 2 CREATE (n)-[r]->(l)

of course results in duplicate relationships when run twice

which CYPHER should run to merge the duplicate relationships into one, without affecting the nodes?

1 ACCEPTED SOLUTION

clem
Graph Steward

I think this will help, but alas, the page doesn't have any examples, so you'll have to experiment:

This doc also doesn't explain the configure argument, but the config arguments are described with MergeNodes:

https://neo4j-contrib.github.io/neo4j-apoc-procedures/3.5/graph-refactoring/merge-nodes/

View solution in original post

2 REPLIES 2

dana_canzano
Neo4j
Neo4j

I'm not sure this works as your cypher is

MATCH(a) WHERE ID(a) =1 MATCH(b) WHERE ID(b) = 2 CREATE (n)-[r]->(l)

and your create references a node aliased as n and one aliased as l but I do not see where n or l defined.

Are you simply trying to create 1 relationship between node a and node b and if the above is run multiple times it should always result in only 1 relationship between a and b? Also, your relationship has no type. Is that what you want?

Maybe something similar to

MATCH(a) WHERE ID(a) =1 MATCH(b) WHERE ID(b) = 2 CREATE (a)-[:MY_RELATIONSHIP_TYPE]->(b)

clem
Graph Steward

I think this will help, but alas, the page doesn't have any examples, so you'll have to experiment:

This doc also doesn't explain the configure argument, but the config arguments are described with MergeNodes:

https://neo4j-contrib.github.io/neo4j-apoc-procedures/3.5/graph-refactoring/merge-nodes/

Nodes 2022
Nodes
NODES 2022, Neo4j Online Education Summit

On November 16 and 17 for 24 hours across all timezones, you’ll learn about best practices for beginners and experts alike.