Reputation: 29
I have this nodes in my neo4j. It is about a Family tree.
Here is the picture:Graph View
I want to find the all the neighbors for a given node from the leaf. Is that possible? can anyone help me?
explanation:
This Cypher query returns all the grandchildren for 'Lucas Hankinson':
MATCH(n:FamilyTree{name: 'Lucas Hankinson'})-[*2..2]->(m) RETURN collect(m)
If I was given the name of one of Lucas's grandchildren and I want to see all his/her cousins and siblings(basically the neighbor nodes of that grandchild) how can I do that in a Cypher Query.
Upvotes: 0
Views: 2494
Reputation: 110
You can try using the path notion. e.g. From the given Grand Child name (e.g. Elwood Alger) find the Grand Parent using path (in this case Lucas Hankinson) and then find all the Grand Children.
Query:
MATCH (gc:FamilyTree{name: 'Elwood Alger'})<--(p:FamilyTree)<--(gp:FamilyTree)
OPTIONAL MATCH (gp) -[*2..2]->(m) WHERE m.name <> 'Elwood Alger' RETURN collect(m)
Thanks, Vishal
Upvotes: 2