billDickens
billDickens

Reputation: 111

How do I get a list of Neo4j nodes in a directed graph starting from a subnode?

I have a very large graph that has one root node that fans out into multiple nodes. I need to get a list of ALL of the nodes in the subgraph. Other than label, they don't have a common attribute. They are only connected by the "connections"

enter image description here

Looking at my very simplified graph, I wanted to start from B

MATCH (n: {label:'B'}) and get a list of all the subnodes [E,C,H,F]

or Start with D and get [G] or start with C and get [H,F]

I though this would get me where I needed to go

https://neo4j.com/labs/apoc/4.1/graph-querying/expand-subgraph/

But i can't get the results.

Upvotes: 0

Views: 146

Answers (1)

cybersam
cybersam

Reputation: 66989

Something like this should get all the nodes in the B subtree (including the B node).

MATCH p=(:Foo {label: 'B'})-[*0..]->(n)
RETURN n

Warning: Variable length relationships without a reasonable upper bound can run for a very long time and/or run out of memory.

Upvotes: 1

Related Questions