Search code examples
neo4jcypher

How to filter path results based on a specific node with a specific property


enter image description here

I have a query to find the paths between two nodes. Now, I want to find any paths that have a node with a status = 'down'. However, the only query that works is to find paths without any nodes with a status of down.

Here is the query that is able to give me all the paths without a node with a status = 'down'.

MATCH path=((dev)-[r:part_of|CONNECTS*..20]-(dev2))
WHERE dev.hostname = 'fwmc0208-01' AND dev2.hostname = 'cemc0208-01.edg'
WITH nodes(path) AS n
  WHERE NONE(node IN n WHERE (node.status IS NOT NULL) and node.status = 'down')
RETURN n

enter image description here

If I replace NONE with ALL, I get zero results. I've tried flipping the status to equal 'up', but this doesn't work either.


Solution

  • You should use the ANY function:

    MATCH path=((dev)-[r:part_of|CONNECTS*..20]-(dev2))
    WHERE dev.hostname = 'fwmc0208-01' AND dev2.hostname = 'cemc0208-01.edg'
    WITH nodes(path) AS n
      WHERE ANY(node IN n WHERE (node.status IS NOT NULL) and node.status = 'down')
    RETURN n