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

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

2 Likes