cancel
Showing results for 
Search instead for 
Did you mean: 

Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.

How do I get the k-hop neighborhood of a node in a directed graph?

Hi to everyone!

Is there some neo4j algorithm that will return the k-hop neighborhood of a root/seed node?

  • Neo4j desktop 3.5.16

Thanks!
Andreas

1 ACCEPTED SOLUTION

Hello @and.manousakis,

This cypher request allows to get all nodes in the neighborhood of the root node:

MATCH(root:Product{pid:123})-[r*..k]->(d)
RETURN DISTINCT(d)

If you want to have more information, this is the link to the doc: https://neo4j.com/docs/cypher-manual/current/clauses/match/#relationships-in-depth

Regards,
Cobra

View solution in original post

1 REPLY 1

Hello @and.manousakis,

This cypher request allows to get all nodes in the neighborhood of the root node:

MATCH(root:Product{pid:123})-[r*..k]->(d)
RETURN DISTINCT(d)

If you want to have more information, this is the link to the doc: https://neo4j.com/docs/cypher-manual/current/clauses/match/#relationships-in-depth

Regards,
Cobra