Given are 2 nodes of type "System" and i want to set a property and create a missing relation (and a node if it not exist)
Example:
MATCH (s:System {Name: 'system1'})
SET s.ClusterPartner = 'system2'
WITH s
WHERE has(s.ClusterPartner)
CREATE UNIQUE (s)-[:ClusteredWith]-(c:System {Name: s.ClusterPartner})
Before that query i've 2 Nodes of type "System" and both have their Name property set correctly ('system1' and 'system2') without any relation between them.
This query will not just create the missing relation, it also creates a new node with the name 'system2', even when it exists.
Maybe i've not understood the docs, but i think it should just create the missing relation in my case and only relation and a new node when 'system2' node does not exists.
What is the problem with this query?
Update1: using the merge approach:
MATCH (s:System {Name: 'system1'})
SET s.ClusterPartner = 'system2'
WITH s
WHERE has(s.ClusterPartner)
MERGE (c:System {Name : s.ClusterPartner})
MERGE (s)-[:ClusteredWith]->(c)
will also create a new unlabled node.
Update2: using the merge and create approach:
MATCH (s:System {Name: 'system1'})
SET s.ClusterPartner = 'system2'
WITH s
WHERE has(s.ClusterPartner)
MERGE (c:System {Name : s.ClusterPartner})
CREATE UNIQUE (s)-[:ClusteredWith]-(c)
looks like this one works as expected
MERGE
query doesn't work as expected? I ranCREATE (s:System { Name: 'system1' }),(:System { Name: 'system2' })
and pasted your query from "update1" and that seems to work fine. – jjaderberg