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.

Remove duplicate links between nodes

For instance there are like 500 nodes connected to a node "X", the node "X" is connected to node "Y", between node "X" and "Y" there are 500 strings/relationship lines. I know the reason it occurs, but can I have one string/relationship line instead of 500 strings between 2 nodes?

Thanks in advance.

1 ACCEPTED SOLUTION

@vence.andersen17

You could try something like this:

match (p:X)-[rel]->(q:Y) // match rels
with p, q, tail(collect(rel)) as rels // with tail we pick all rels except the first one
foreach(x in rels | delete x) // remove all rels except the 1st

View solution in original post

4 REPLIES 4

@vence.andersen17

You could try something like this:

match (p:X)-[rel]->(q:Y) // match rels
with p, q, tail(collect(rel)) as rels // with tail we pick all rels except the first one
foreach(x in rels | delete x) // remove all rels except the 1st

omerule
Graph Buddy

Maybe it is also possible to prevent the creations of these relation with use of MERGE.

Yours kindly,
Omer

I am actually creating nodes with merge, how do you suggest it to do?

Sorry, I am confused. Do you want help avoiding the creation of the 500 relationships? If so, can you provide the code that creates the relationships?