我有这个cypher查询来插入10,000个节点。这很好用。
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
现在,20个新节点与已存在的其他节点建立[:contact]关系。我的查询创建了20,000个额外节点,运行速度非常慢。我知道merge有一些重复问题。如何让这段代码运行得更快?
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;
答案 0 :(得分:1)
首先,您的第二个查询是错误的,因为您正在搜索 mobileNubmer ,而不是 mobileNumber 。其次, mobileNumber 应该是User的唯一约束。第三(鉴于约束已经到位),这应该是你的语法:
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;
希望这有帮助。
此致 汤姆