Neo4j: How do I delete a specific relationship with cypher?

user405398 picture user405398 · Sep 26, 2013 · Viewed 27.3k times · Source

Lets say, I have an user:

CREATE (n { name: 'Tamil' })

and 2 roles:

CREATE (n { name: 'developer' } ) 
CREATE (n { name: 'tester' } )

Then, I make relationship between the user & each of the 2 roles.

CYPHER 1.9  START a = node(*), b = node(*) 
WHERE a.name = 'Tamil' AND b.name = 'developer' 
CREATE (a)-[r:HAS_ROLE]->(b) 
RETURN r

CYPHER 1.9  START a = node(*), b = node(*) 
WHERE a.name = 'Tamil' AND b.name = 'tester' 
CREATE (a)-[r:HAS_ROLE]->(b) 
RETURN r

Now, I want to remove tester role relationship from the user. I tried:

CYPHER 1.9  START a = node:node_auto_index('name:Tamil') 
MATCH a-[r:HAS_ROLE]-() 
RETURN r

But, it returns both of the relationships. I know that i can attach property with relationships. But, again, I don't know the cypher syntax for that.

I am new to Neo4j. Any suggestions would be really great!

Thanks!

Answer

Werner Kvalem Vesterås picture Werner Kvalem Vesterås · Sep 26, 2013

I deleted the relationship on your original graph with this query:

START n=node(*) 
MATCH (n)-[rel:HAS_ROLE]->(r) 
WHERE n.name='Tamil' AND r.name='tester' 
DELETE rel