In Neo4J, how do I write a Cypher query that shows all the nodes that connect to an initial node by a specific number of paths?
Asked
Active
Viewed 464 times
2 Answers
1
Number of paths or number of hops?
start n=node(x)
match path = n-[:TYPE*..3]->end // number of hops *..3 is up to 3 hops
return path
limit 10 // number of paths

Michael Hunger
- 41,339
- 3
- 57
- 80
-
1Is there a way to do the same thing but returning only simple paths (no repeated nodes)? See here: http://stackoverflow.com/questions/13767748/returning-only-simple-paths-in-neo4j-cypher-query – Marsellus Wallace Dec 12 '12 at 15:06
0
I think maybe he's looking for:
start n=node(x)
match path = n-[*]->end // maybe specify a max length and type?
with count(path) as cnt, end // group by end node, get count of paths
where cnt = <numpaths> // replace <numpaths> with the number of paths you want to match
return end

Eve Freeman
- 32,467
- 4
- 86
- 101