Hello,
I'm looking for a way to stop traversing a subgraph when there is at least one relationship of the certain type.
I have a similar approach for the nodes labels. I add a label Excluded
on the nodes I want to exclude for some reasons, use apoc.path.subgraphNodes
, and add labelFilter: "-Excluded"
.
I'd want to make this approach more granular and exclude relationships instead of nodes. Unfortunately relationshipFilter
does not support the same syntax as labelFilter
and I can't specify relationshipFilter: "-Excluded"
to have a query like that:
MATCH (n: A {id: $node_id})
CALL apoc.path.subgraphNodes(
n,
{{
filterStartNode: false,
maxLevel: $max_level,
minLevel: $min_level,
labelFilter: "-Excluded|SomeOtherFilters",
relationshipFilter: "-Excluded|SomeOtherFilters",
limit: $limit
}}
)
YIELD node
RETURN node
Data model looks like that :
MERGE (a: A {id: 1} )
MERGE (b1:B {id: 1})
MERGE (b2:B {id: 2})
MERGE (a) - [:UsedRelA] -> (b1)
MERGE (a) - [:Excluded] -> (b1)
MERGE (a) - [:UsedRelA] -> (b2)
I want to run a query that will get me all the nodes connected to node a using a relationship UsedRelA
and does not have a relationship Excluded
. So in this case it will return nodes a
, and b2
but not b1
as it has a connection Excluded
.
I was trying to achieve it using the new cypher syntax but I don't get the desired result neither.
MATCH (a:A)-[r where r.relType <> "Excluded"]-{,}(b:B) return *
Is it possible to make this kind of filtering? I'm especially interested in the solution using apoc.path.subgraphNodes
as it has a lot better performance than pure cypher.
UPD:
I prefer to use apoc as the real data have a lot of nodes and multiple hops relationships.
The results could have 5+ hops with 10k+ nodes, and so far I didn't find a way to use pure cypher that will be at least close to the same apoc performance.
Thanks for your help!