是否有关于MERGE关系的独特ON CREATE和ON MATCH的解决方案?
例如:
USING PERIODIC COMMIT 10000
LOAD CSV WITH HEADERS FROM 'http://ip/myfile.csv' AS row
MATCH (source:Ticket {Id: toInt(row.idticket)})
MATCH (target:User {Id: toInt(row.iduser)})
MERGE (source)-[rel:`AskBy` {}]->(target);
做这样的事情
USING PERIODIC COMMIT 10000
LOAD CSV WITH HEADERS FROM 'http://ip/myfile.csv' AS row
MATCH (source:Ticket {Id: toInt(row.idticket)})
MATCH (target:User {Id: toInt(row.iduser)})
MATCH (source)-[rel:`AskBy` {}]->(target);
ON CREATE SET (source)-[rel:`AskBy` {createDate: timespan()}]->(target)
ON MATCH SET (source)-[rel:`AskBy` {updateDate: timespan()}]->(target)
我想区分关系的创建日期和更新日期
谢谢
答案 0 :(得分:0)
您只需要设置属性:
MATCH (source:Ticket {Id: toInt(row.idticket)})
MATCH (target:User {Id: toInt(row.iduser)})
MERGE (source)-[rel:AskBy]->(target)
ON CREATE SET rel.createDate = timestamp()
ON MATCH SET rel.updateDate = timestamp();
答案 1 :(得分:0)
要回答@ NicoleWhite正确回答的评论中的后续问题:
MERGE
不允许任何条件。如果它不匹配,它将始终创建指定的模式。以下是如何实现"条件MERGE"等效的示例。使用OPTIONAL MATCH
和FOREACH
作为解决方法。
这个例子假装这是所需的伪逻辑:
如果AskBy
关系不存在:
source.priority
值大于10,则创建关系(使用createDate
属性)否则设置其updateDate
属性。
USING PERIODIC COMMIT 10000
LOAD CSV WITH HEADERS FROM 'http://ip/myfile.csv' AS row
MATCH (source:Ticket {Id: toInt(row.idticket)})
MATCH (target:User {Id: toInt(row.iduser)})
OPTIONAL MATCH (source)-[rel:AskBy]->(target)
WITH source, rel, target,
(CASE
WHEN rel IS NULL AND source.priority > 10 THEN {create: [1]}
WHEN rel IS NULL THEN NULL
ELSE {set: [1]}
END) AS todo
FOREACH (x IN todo.create | CREATE (source)-[rel:AskBy {createDate: timestamp()}]->(target))
FOREACH (x IN todo.set | SET rel.updateDate = timestamp())