0
votes

I'm trying to create multiple relations at once, all going out from one node, entering multiple other nodes. I'm trying to use MERGE in order to match/create the nodes, and then CREATE to create multiple relations at once. The problem is that for some reason the relations are being duplicated, each relation is being created twice... help?

my JSON request:

{
"query":"MERGE (n:person {subject:'testSubject'}) MERGE (n1:node {subject:'7f975f24-acc9-4400-9b2f-f7fd955425b7'}) MERGE (n2:node {subject:'a8d242b0-5cce-4c00-8912-885c97f917a3'}) ... MERGE (n60:node {subject:'68ee8e74-205a-4ba8-b6d0-6edb8d907912'}) CREATE (n)-[r1:relationToNode { json1 }]->(n1) CREATE (n)-[r2:actsIn { json2 }]->(n2) ... CREATE (n)-[r60:actsIn { json60 }]->(n60)",
"params":{
    "json1":{...}, "json2":{...}, ..., "json60":{...}
}

}

2

2 Answers

1
votes

Is it possible that you ran this query twice? If so, you could have avoided duplicating the relationships by using MERGE instead of CREATE for the relationships.

0
votes

Solved!! Apparently neo4j (2.2.3) duplicates ALL relations for every duplicated node.. I had one duplicated node in the MERGE section and that caused every relation to be created twice.. when I tried the same query when my DB contained tripled nodes the relations were created three times.. solved by using CONSTRAINT unique on the subject field, apparently MERGE is not thread safe by itself.