I have a dataset for a family tree in Neo4J, and I'm trying to build a Cypher request that creates a JSON dataset similar to the following:
{Name: "Bob", parents: [ {Name: "Roger", parents: [ Name: "Robert", Name: "Jessica" ]}, {Name: "Susan", parents: [ Name: "George", Name: "Susan" ]} ]}
My graph has a PARENT relationship between MEMBER nodes (i.e. MATCH (p.Member) - [: PARENT] → (c.Member)). I found the has_many Nesting in cypher and neo4j cypher a nested collection that ultimately groups all the parents together for the main child node I'm looking for.
Adding some clarity based on feedback:
Each member has a unique identifier. Unions are currently all connected with the PARENT relationship. Everything is indexed so that performance is not affected. When I run the query to just return the node graph, I get the expected results. I am trying to return output that I can use for visualization using D3. Ideally, this will be done using a Cypher request, as I use the API to access neo4j from the built-in interface.
Adding an example query:
MATCH (p:Person)-[:PARENT*1..5]->(c:Person) WHERE c.FirstName = 'Bob' RETURN p.FirstName, c.FirstName
This query returns a list of each parent for five generations, but instead of showing a hierarchy, it lists “Bob” as a child of each link. Is there a Cypher query that will show every relationship in the data at least? I can format it as I need from there ...
source share