问题
I am having a issue to retrieve path in neo4j exclude certain label.
Foe example, I have
-->(h)-->(j)
/
(a)-->(b)-->(c)-->(d)-->(i)
\
-->(f)-->(g)
with h
node has a Deleted
label.
I have query
MATCH path = (n)-[*]->(child) where id(n)={id of node a} and NOT child:Deleted RETURN path
then I want this query to return the full path but exclude the subtree of node h
since node h
is Deleted
.
the return tree should be like
(a)-->(b)-->(c)-->(d)-->(i)
\
-->(f)-->(g)
But the query seems not working.
Can any one help me with this.
Thanks
回答1:
What worked for me is a list comprehension over nodes in the path:
MATCH path = ()-[*]->()
WHERE NONE(n IN nodes(path) WHERE n:Deleted)
RETURN path
回答2:
You can use APOC Procedures with this, using the path expander functionality along with a blacklist to prevent expanding to nodes with labels in the blacklist during traversal.
match (a)
where id(a) = {id of node a}
call apoc.path.expandConfig(a, {labelFilter:'-Deleted'}) yield path
return path
回答3:
You need to check both nodes for the label:
match p=((a)-[r:NEXT]->(b))
where not (a:Deleted or b:Deleted)
return p
here's another example:
match (a)-[r:NEXT]->(b)
where not (("Deleted" in labels(a)) or
("Deleted" in labels(b)))
return a, r, b
来源:https://stackoverflow.com/questions/36439749/neo4j-match-path-exclude-node-with-certain-label