我在图数据库,原始机场和目的地机场创建了2个节点。它与名为' delayed_by'的属性相关联。我需要将多个值关联到此属性' delayed_by'。延迟有多种原因,如天气延迟,载波延迟,延迟时间,我需要将它们全部链接到图形数据库中的此属性。我期待图形数据库
中表格格式以下的值ORIGIN DEST carr_delay weather_delay nas_delay
ABE ATL 492 56 56
我使用以下代码表示关系:
MATCH (origin:origin_airport {name: row.ORIGIN}),
(destination:dest_airport {name: row.DEST})
CREATE (origin)-[:delayed_by {carr_delay: row.carr_delay}]->(destination)
CREATE (origin)-[:delayed_by {weather_delay: row.weather_delay}]->
(destination)
CREATE (origin)-[:delayed_by {nas_delay: row.nas_delay}]->(destination)
但是delayed_by关系被映射了3次,它产生如下所示:
ORIGIN DEST carr_delay weather_delay nas_delay
ABE ATL 492 NULL NULL
ORIGIN DEST carr_delay weather_delay nas_delay
ABE ATL NULL 56 NULL
ORIGIN DEST carr_delay weather_delay nas_delay
ABE ATL NULL NULL 56
我尝试使用下面的代码,如另一篇文章中所建议的那样,
MATCH (origin:origin_airport {name: row.ORIGIN}),
(destination:dest_airport {name: row.DEST})
CREATE (origin)
-[:delayed_by {type: carr_delay, value: row.carr_delay}]->
(destination)
CREATE (origin)
-[:delayed_by {type: weather_delay, value: row.weather_delay}]->
(destination)
CREATE (origin)
-[:delayed_by {type: nas_delay, value: row.nas_delay}]->
(destination)
但它不接受type:,value:属性,我在类型
时收到错误Error: Client error: (400) Bad Request
Neo.ClientError.Statement.SyntaxError
如何在Neo4j中使用cypher查询向属性添加多个值?我通过将R连接到Neo4j来在R中编写这些查询。
答案 0 :(得分:2)
这是LOAD CSV Cypher声明的样子 -
LOAD CSV WITH HEADERS FROM "file:///Users/luanne/temp/so.csv" AS row
MERGE (origin:origin_airport {name: row.ORIGIN})
MERGE (destination:dest_airport {name: row.DEST})
MERGE (origin)-[r:delayed_by]->(destination)
SET r.carr_delay=row.carr_delay, r.weather_delay=row.weather_delay, r.nas_delay=row.nas_delay
您希望合并两个机场之间的关系,最终只有一个delayed_by
关系。或者,如果每组机场都有一行,则可以将该关系的MERGE更改为CREATE。
答案 1 :(得分:1)
你有一个错字,你忘记了引号:
CREATE (origin)
-[:delayed_by {type: carr_delay, value: row.carr_delay}]->
(destination)
=>
CREATE (origin)
-[:delayed_by {type: "carr_delay", value: row.carr_delay}]->
(destination)