Get all nodes with a specific type of relationship to a root node

502 Views Asked by At

I have a rather large and complex graph in Neo4j (millions of nodes and relationships in various types), I want to get all child nodes (in all depths) of a specific root node, but only with a specific type of relationship

I have tried: Match (n:NODE_TYPE)-[*:REL_TYPE]->(r:NODE_TYPE {id:SPECIFIC_ID}) return n But I get a syntax error for specifying a label on the relationship

Querying the whole graph takes a really long time without specifying the relationship type, and nodes could go through paths that will eventually lead to the root node but will use other types of relationships (which is not good for my use case)

1

There are 1 best solutions below

0
On BEST ANSWER

you need to change the order of the rel type and wildcard operator:

Match (n:NODE_TYPE)-[:REL_TYPE*]->(r:NODE_TYPE {id:SPECIFIC_ID}) 
return n