Neo4j: Best way to batch relate nodes using Cypher?

后端 未结 2 1726
不思量自难忘°
不思量自难忘° 2021-01-25 21:22

When I run a script that tries to batch merge all nodes a certain types, I am getting some weird performance results.

When merging 2 collections of nodes (~42k) and (~26

2条回答
  •  遇见更好的自我
    2021-01-25 21:55

    Can you pass the ids in as parameters rather than fetch them from the graph? The query could look like

    MATCH (s:ContactPlayer {ContactPrefixTypeId:{cptid})
    MERGE (c:ContactPrefixType {ContactPrefixTypeId:{cptid})
    MERGE c-[:CONTACT_PLAYER]->s
    

    If you use the REST API Cypher resource, I think the entity should look something like

    {
        "query":...,
        "params": {
            "cptid":id1
        }
    }
    

    If you use the transactional endpoint, it should look something like this. You control transaction size by the number of statements in each call, and also by the number of calls before you commit. More here.

    {
        "statements":[
            "statement":...,
            "parameters": {
                "cptid":id1
            },
            "statement":...,
            "parameters": {
                "cptid":id2
            }
        ]
    }
    

提交回复
热议问题