加载CSV,匹配节点,合并关系并将新值推送到数组属性

时间:2019-04-08 02:30:45

标签: neo4j cypher

如何匹配CSV加载中的节点并将每个匹配中的值推入关系的array属性中?

LOAD CSV WITH HEADERS FROM 'http://example.com/horse_races.csv' AS line
MATCH (j:Jockey { name: line.JOCKEY_NAME})
MATCH (h:Horse { name: line.HORSE_NAME})
MERGE (j)-[r:JOCKEYED]->(h)
ON MATCH SET r.date = r.date + date(line.RACE_DATE)

1 个答案:

答案 0 :(得分:1)

当前在merge上,您仅在关系已经存在的情况下为该关系设置日期。您可以设置on create来初始化尚不存在的列表:

LOAD CSV WITH HEADERS FROM 'file:///jockeys.csv' AS line 
with distinct line MATCH (j:Jockey { name: line.JOCKEY_NAME}), (h:Horse { name: line.HORSE_NAME}) 
MERGE (j)-[r:JOCKEYED]->(h) ON CREATE SET r.date = [line.RACE_DATE] 
ON MATCH SET r.date = r.date + date(line.RACE_DATE)