siddhusingh
siddhusingh

Reputation: 1868

Neo4J : Get all nodes who are connected to at least K nodes with a path length <= 2

With this use case I am finding it to hard with Cypher query. Do I need to write stored procedure for it ?

Upvotes: 0

Views: 188

Answers (1)

cybersam
cybersam

Reputation: 67009

Here is a query that will return every node that is connected via paths up to length 2 to at least k distinct nodes. k is assumed to be passed as a parameter.

MATCH (n)-[*..2]-(m)
WITH n, COUNT(DISTINCT m) AS ms
WHERE ms > $k
RETURN n, ms;

Upvotes: 2

Related Questions