Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.
06-09-2019 04:03 PM
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()
06-09-2019 05:10 PM
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.
06-10-2019 12:48 PM
Great. Thanks Andrew. Works perfectly giving me the results I was seeking.
All the sessions of the conference are now available online