neo4jcypher

Neo4j matching multiple association labels


In a Neo4j database, I'd like to find everything pointing to a single record of interest, and filter these relations by their label. I can do this with a single label like this:

MATCH path = (r:`Neo4j::Record` {record_id: 1236})<-[:`Neo4j::RecordAssociation` {label: 'Part Of'}]-{0,10} ()
RETURN path, length(path) AS hops
ORDER BY hops

...but, there are some additional labels on records a few hops away from 1236, e.g. 'Related To', 'Recommends' etc. and I'd like to include those as well.

Is there any way to modify the {label: 'Part Of'} part of the above query, or some other modification, which would allow matching 'Part Of' OR 'Related To' OR 'Recommends' ?


Solution

  • MATCH path = (r:`Neo4j::Record` {record_id: 1236})
      <-[n:`Neo4j::RecordAssociation` 
           WHERE n.label IN ['Part Of', 'Related To', 'Recommends']]-{0,10} ()
    RETURN path, length(path) AS hops
    ORDER BY hops