you can also use the path directly then you can specify a minimum length too and you should use a newer version of Neo4j.
MATCH (person:Person) OPTIONAL MATCH (person)-[:KNOWS]-(p:Person) WITH person, count(p) as f1 OPTIONAL MATCH (person)-[:KNOWS*2]-(f2:Person) WITH count(distinct f2) as f2, person, f1 OPTIONAL MATCH (person)-[:KNOWS*3]-(f3:Person) WITH count(distinct f3) AS f3, person, f2, f1 RETURN person._firstName + " " + person._lastName, f1, f2, f3 you should also profile your query, then you see how much data it touches. Something else that should work too is: MATCH (person:Person) OPTIONAL MATCH path = (person)-[:KNOWS*..3]-(:Person) WITH person, count(distinct nodes(path)[1]) as f1, count(distinct nodes(path)[2]) as f2, count(distinct nodes(path)[3]) as f3 RETURN person._firstName + " " + person._lastName,f1,f2,f3 Michael > Am 16.03.2016 um 00:42 schrieb Michael Azerhad <[email protected]>: > > shortestPath returns the right results. > Without it, wrong results. > > -- > You received this message because you are subscribed to the Google Groups > "Neo4j" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to [email protected] > <mailto:[email protected]>. > For more options, visit https://groups.google.com/d/optout > <https://groups.google.com/d/optout>. -- You received this message because you are subscribed to the Google Groups "Neo4j" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. For more options, visit https://groups.google.com/d/optout.
