I have Profile node which may be linked to Location node via :LOCATED_IN relationship.
In turn, Location represents unlimited composite structure of nested Location nodes linked with :CONTAINS relationships between them.
I need to find all Profiles which linked to specified location IDs or their parent locations on unlimited levels.
I'm trying to create such Cypher query but it doesn't work as expected. This is what I have so far:
MATCH (d:Profile)-[:LOCATED_IN]-(l:Location) OPTIONAL MATCH (pl:Location)-[:CONTAINS*]->(l) WHERE any(x IN l.id WHERE x IN ) OR any(x IN pl.id WHERE x IN ) return d;