Now, REL1 and REL2 can be modelled either as 2 relationship types that can COEXIST between 2 nodes or the same relationship type ( REL ) with different relationship properties. What is the most performant / efficient way to model and query the following scenario: - start from Node a and find nodes c and e that are connected with REL2 with the next node ( d and f ) in the path
Great, thank you!
I am not sure how it would work with relationship properties (single rel type REL) when one cannot use property filtering in WHERE EXISTS
I am having a difficult time understanding the requirements, but you can try something like this if you can't add more specific constraints to your pattern. The following allows you to specify relationship criteria that can occur anywhere along the path. Add multiple 'Any' clauses for each relationship criteria you want along the path. The example shows criteria having a mixture of property and relationship type criteria.
match p = (:Node {name:'a'})-[:REL1|REL2*]->(:Node {name:'f'})
with p, relationships(p) as relationships
where any(i in relationships where i.relationshipProperty = 'value' and i:REL1)
and any(i in relationships where i. i.relationshipProperty = 'value2' and i:REL2)
and any(i in relationships where i. i.relationshipProperty = 'value3')
return p
The accepted solution works when there are two types of relationships in the path: REL1 and REL2
I am looking for the solution in case there is a single relationship type: REL and I need to find nodes in the path, which have OUTGOING relationship of type REL with property rank > rank on the first relationship in the path:
match p=(:Node{name:'a'})-[:REL*]->(:Node{name:'root'})
with relationships(p) as relationships
with relationships[0] as first, tail(relationships) as remaining
with [i in remaining where i.rank > first.rank] as filtered
unwind filtered as relationship
return startNode(relationship) as result