Neo4j Cypher - Type relationship exception in cypher request?

Individual relationships may be excluded by types using

Match (n:Person)-[r]-(m:Person) where type(r)<>"FRIENDS" return n,r,m 

Is there a way to eliminate multi-level relationships with cypher?

 Match (n:Person)-[r*2..4]-(h:Hobby) where type(r)<>"FRIENDS" return n,r,h 
+5
source share
2 answers

Of course you can do it. Like this:

 Match (n:Person)-[r*2..4]-(h:Hobby) where NONE( rel in r WHERE type(rel)="FRIENDS") return n,r,h 

Your query does not work, because with multi-level paths, your r is a collection of relationships, not one. Thus, you can use any predicates in collections to perform the necessary filtering.

Here I chose NONE with type (rel) = FRIENDS, which means that you will only get results if NONE relationships are of type FRIENDS. But instead, you can use ANY or EVERYTHING, depending on what your request should mean.

In any case, the main point here is to use the predicate function to turn a collection of things into one logical value.

+7
source

You can use the ALL or ANY predicates for this:

 MATCH p=(n:Person)-[*2..4]-(h:Hobby) WHERE ALL(x in relationships(p) WHERE type(x) <> "FRIENDS") RETURN n,r,h 

Use the ALL predicate to ensure that all relationships along this path are not FRIEND . Use ANY to make sure you have at least one relationship other than FRIEND .

+2
source

All Articles