Creating Family Tree with Neo4J

前端 未结 4 1656
囚心锁ツ
囚心锁ツ 2020-12-29 00:50

I have a set of data for a family tree in Neo4J and am trying to build a Cypher query that produces a JSON data set similar to the following:

{Name:  \"Bob\"         


        
4条回答
  •  太阳男子
    2020-12-29 01:37

    You might also have a look at Rik van Bruggens Blog on his family data:

    Regarding your query

    You already create a path pattern here: (p:Person)-[:PARENT*1..5]->(c:Person) you can assign it to a variable tree and then operate on that variable, e.g. returning the tree, or nodes(tree) or rels(tree) or operate on that collection in other ways:

    MATCH tree = (p:Person)-[:PARENT*1..5]->(c:Person)
    WHERE c.FirstName = 'Bob'
    RETURN nodes(tree), rels(tree), tree, length(tree),
           [n in nodes(tree) | n.FirstName] as names
    

    See also the cypher reference card: http://neo4j.com/docs/stable/cypher-refcard and the online training http://neo4j.com/online-training to learn more about Cypher.

    Don't forget to

    create index on :Person(FirstName);
    

提交回复
热议问题