Path that contains specific nodes in the middle?

201 Views Asked by At

In Cypher you can get path anchored on two nodes f.e.

 match path=(a)-[r:rel*1..5]->(b)
 where a.val = 1 and b.val = 2
 return path

the question is how can I get paths that contain say node '(x) where x.val = 5' in the middle, instead of all paths

1

There are 1 best solutions below

0
On

You can add to the where clause

AND ANY(x IN nodes(path)[1..-1] WHERE x.val =5)

to get paths through at least one node that has val=5