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)

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, 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.

1 Like

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