Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Neo4j match path exclude node with certain label

Tags:

neo4j

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

like image 214
jasonfungsing Avatar asked Apr 06 '16 01:04

jasonfungsing


People also ask

What is the syntax for getting all the nodes under specific label in Neo4j?

If you want to get the labels of a specify node, then use labels(node) ; If you only want to get all node labels in neo4j, then use this function instead: call db. labels; , never ever use this query: MATCH n RETURN DISTINCT LABELS(n) .

What is optional match in Neo4j?

An OPTIONAL MATCH matches patterns against your graph database, just like a MATCH does. The difference is that if no matches are found, OPTIONAL MATCH will use a null for missing parts of the pattern. OPTIONAL MATCH could be considered the Cypher equivalent of the outer join in SQL.

Can u relabel node in Neo4j?

You can change the nodes associated with a label but you can't change the type of a relationship. Conceptually, if you take your chicken out of one coop and put it in another you haven't altered the substance of the chicken.

How do you escape special characters in database user and role names Neo4j?

Non-alphabetic characters, including numbers, symbols and whitespace characters, can be used in names, but must be escaped using backticks. For example: `^n` , `1first` , `$$n` , and `my variable has spaces` .


1 Answers

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
like image 149
weekens Avatar answered Sep 28 '22 07:09

weekens