Creating Family Tree with Neo4J

前端 未结 4 1647
囚心锁ツ
囚心锁ツ 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条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-12-29 01:17

    I'd suggest building a method to flatten out your data into an array. If they objects don't have UUIDs you would probably want to give them IDs as you flatten and then have a parent_id key for each record.

    You can then run it as a set of cypher queries (either making multiple requests to the query REST API, or using the batch REST API) or alternatively dump the data to CSV and use cypher's LOAD CSV command to load the objects.

    An example cypher command with params would be:

    CREATE (:Member {uuid: {uuid}, name: {name}}
    

    And then running through the list again with the parent and child IDs:

    MATCH (m1:Member {uuid: {uuid1}}), (m2:Member {uuid: {uuid2}})
    CREATE m1<-[:PARENT]-m2
    

    Make sure to have an index on the ID for members!

提交回复
热议问题