How to avoid adding a new relationship if another already exists between two nodes

We import relationships between specific nodes from a CSV file. We then synthesize potential relationships between the same two nodes. How can we create a set of queries to add the synthetic relationship only if the real relationship doesn't already exist?

I tried a number of "patterns" to no avail. The only method I have as a newbie is:
MATCH (origin)-[real:REAL]-(destination)
MATCH (origin)-[synth:SYNTHETIC]-(destination)
DELETE synth

Not very elegant...

TIA,
Paolo

You could try the follow. I assume you will add specific property and label constrains to the match entities.

MATCH (origin), (destination)
WHERE NOT EXISTS((origin)-[real:REAL]-(destination))
CREATE (origin)-[synth:SYNTHETIC]-(destination)

Thanks @glilienfield , after applying the constraints, it works fine, We have two slightly different situations at present, and we got it working in both.

Thanks, again!

Paolo

1 Like