cancel
Showing results forΒ
Did you mean:Β

## Check different conditions on parts of a path depending of type of relationships and labels of nodes

Node

I'm trying to target specific loops in my graph depending on their length and the nature of the nodes and relationships contributing to these loops. My query is still incomplete because I would rely on an "EXISTS" clause in a place it's not allowed to and I'd like ideas for workarounds

Here is part of my cypher code, a bit simplified and abstracted

``````MATCH
p_3 = shortestPath((s:S)-[:R_D|R_M|R_G*1..10]-(t:Entity)) WHERE s<>t
WITH a,e,b, nodes(p_3) as nds, relationships(p_3) as rels
WHERE ALL(
r IN rels WHERE (
(
type(r)='R_D'
AND (
r.prop IS NULL
OR r.prop > 37
)
) OR (
type(r)='R_M' AND NOT startNode(r):Person
) OR (
type(r)='R_M' AND startNode(r):Person AND r.code = 30
) OR (
type(r)='R_G'
)))
RETURN * LIMIT 1000;
``````

As you can see one side of the loop is perfectly described (some entity owns a building, some establishment's address is the address of said building) while the other side of the loop is a path of variable length involving different possible relationships and nodes types with some conditions to apply to the relations of types R_D and R_M.

Now the missing part, is that the condition

`````` type(r)='R_M' AND startNode(r):Person AND r.code = 30
``````

should be

`````` type(r)='R_M' AND startNode(r):Person AND r.code = 30
AND EXISTS {(startNode(r))-[d:R_M{code:30}]-(si:S{act:123456}) WHERE d IN rels OR si IN nds}
``````

which means that the startNode of the relationship r currently examined in the ALL...WHERE clause must be the startNode of a relation (which can be r on another one) which other node has a specific property value and is in the path p3 too

This addition sparks an error because EXISTS can't be part of a ALL (element IN list WHERE) so how could I fit such a condition in my query ?

0 REPLIES 0
Nodes 2022

NODES 2022, Neo4j Online Education Summit

OnΒ November 16 and 17 for 24 hours across all timezones, youβll learn about best practices for beginners and experts alike.

Neo4j Resources