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.

How to delete all relationships with specific type that do not have certain property name?

I have graph with relationships that have type and some of that relations have property
I want to delete only relationships without property but relation with same type and with property must be untouched

1 ACCEPTED SOLUTION

The following will find all relationships of type ':REL' and delete those that have zero properties. You can add restrictions to the type of nodes it relates as well, if that is needed by adding node labels to the match pattern.

match()-[r:REL]->()
where size(keys(properties(r)))=0
delete r

You should test it first because it can't be undone. maybe execute it with 'return' instead of 'delete' so you can review the relationships it will delete.  

View solution in original post

2 REPLIES 2

The following will find all relationships of type ':REL' and delete those that have zero properties. You can add restrictions to the type of nodes it relates as well, if that is needed by adding node labels to the match pattern.

match()-[r:REL]->()
where size(keys(properties(r)))=0
delete r

You should test it first because it can't be undone. maybe execute it with 'return' instead of 'delete' so you can review the relationships it will delete.  

Thank you, everything works as it should 😊