Creating nodes and relationships at the same time in neo4j

前端 未结 4 643
夕颜
夕颜 2021-02-08 06:06

I am trying to build an database in Neo4j with a structure that contains seven different types of nodes, in total around 4-5000 nodes and between them around 40000 relationships

4条回答
  •  庸人自扰
    2021-02-08 06:31

    You can create multiple nodes and relationships interlinked with a single create statement, like this:

    create (a { name: "foo" })-[:HELLO]->(b {name : "bar"}),
           (c {name: "Baz"})-[:GOODBYE]->(d {name:"Quux"});
    

    So that's one approach, rather than creating each node individually with a single statement, then each relationship with a single statement.

    You can also create multiple relationships from objects by matching first, then creating:

    match (a {name: "foo"}), (d {name:"Quux"}) create (a)-[:BLAH]->(d);
    

    Of course you could have multiple match clauses, and multiple create clauses there.

    You might try to match a given type of node, and then create all necessary relationships from that type of node. You have enough relationships that this is going to take many queries. Make sure you've indexed the property you're using to match the nodes. As your DB gets big, that's going to be important to permit fast lookup of things you're trying to create new relationships off of.

    You haven't specified which query you're running that isn't "stopping loading". Update your question with specifics, and let us know what you've tried, and maybe it's possible to help.

提交回复
热议问题