1
votes

I want to retrieve paths between nodes with constraint on node label. All nodes in the path should hold a specific label. "amps" is my label and My query:

MATCH p=(a:amps{word:"review"})-->()-->()-->(b:amps{word:"nothing"}) 
RETURN p

In the above query, I have two intermediate nodes. Now, I want these two nodes should also hold the label "amps".

How to make comparisons on labels?

1

1 Answers

4
votes

If ALL the nodes in the path should have the amps label and with you current query you can do this in two ways :

1) Specify the labels in the () :

MATCH p=(a:amps{word:"review"})-->(:amps)-->(:amps)-->(b:amps{word:"nothing"}) 
RETURN p

2) Specify it with the ALL predicate :

MATCH p=(a:amps{word:"review"})-->()-->()-->(b:amps{word:"nothing"})
WHERE ALL ( n IN nodes(p) WHERE "amps" IN labels(n) )
RETURN p