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.

Recursive Query with levels

Hi there:
I have created a database with the names and parent_of relationship to depict my extended family.

I am trying to query the database and return the levels of relationship. For example, I am querying my mother, and my sibling and our children all show at the same level.

Is there a way of showing the heirachy or depth of the connection?

MATCH (asha:Person { name:"Choodamani Padmanabhan" })-[:parent_of 1..]->(per: Person)
RETURN per.name, COUNT(
)

2 REPLIES 2

So you want the depth along with the name? If you introduce a path variable for the matched pattern, you can get the length(path) which should give you want you want.

MATCH path = (asha:Person { name:"Choodamani Padmanabhan" })-[:parent_of  *1..]->(per: Person)
RETURN per.name, length(path) as depth

If needed, you can order by the depth as well. Or you could aggregate by the depth, so you would have a list of persons per depth.

Great. Thanks Andrew. Works perfectly giving me the results I was seeking.