1
votes

I have this cypher query to insert 10,000 node. This works nice.

LOAD CSV WITH HEADERS FROM "file:///persons.csv" AS csv
MERGE (u2:User {mobileNumber: csv.mobileNumber})
       ON CREATE SET u2.memberType = csv.memberType
       ON CREATE SET u2.accountId = csv.accountId
       ON CREATE SET u2.accountType = csv.accountType
       ON CREATE SET u2.createdAt = csv.createdAt
       SET u2.updatedAt = csv.updatedAt

Now 20 new node creates [:contact] relationship with some other nodes that already exist. My query creates 20,000 extra nodes and runs very slow. I know merge has some issue with duplication. How can I make this code run faster?

LOAD CSV WITH HEADERS FROM "file:///phonebook.csv" AS csv
MERGE (:User{mobileNubmer: csv.ownerMobileNumber})-[c:CONTACT]->
(:User{mobileNubmer:csv.contactMobileNumber})
    ON CREATE SET c.createdAt = csv.createdAt
    ON MATCH set c.previousIsActive = 
    csv.previousIsActive
    SET c.name = csv.name
    SET c.relationship = csv.relationship
    SET c.isActive = csv.isActive
    SET c.updatedAt = csv.updatedAt;
1
You are using merge incorrectly.Tezra
Please help me to fix itsad_man

1 Answers

1
votes

Firstly, you're second query is wrong because you are searching for mobileNubmer, not mobileNumber. Secondly, mobileNumber should be a unique constraint for User. Thirdly (given the constraint is in place), this should be your syntax :

LOAD CSV WITH HEADERS FROM "file:///phonebook.csv" AS csv
MATCH (owner:User{mobileNumber: csv.ownerMobileNumber})
MATCH (contact:User{mobileNumber: csv.contactMobileNumber})
MERGE (owner)-[c:CONTACT]->(contact)
    ON CREATE SET c.createdAt = csv.createdAt
    ON MATCH set c.previousIsActive = csv.previousIsActive
    SET c.name = csv.name
    SET c.relationship = csv.relationship
    SET c.isActive = csv.isActive
    SET c.updatedAt = csv.updatedAt;

Hope this helps.

Regards, Tom