[英]Create multiple relationships of same type with different properties between two nodes from csv
I am facing issue while creating multiple relationships of same type with different properties between two nodes in Neo4jDesktop. 在Neo4jDesktop中的两个节点之间创建具有不同属性的相同类型的多个关系时,我遇到了问题。
Nodes dataset:
File Name: 1.csv
File Contents:
Id,Desc
A,Alpha
B,Beta
C,Charlie
D,Doyce
Relationships Dataset:
File Name: 2.csv
File Contents:
SeqNo,Date,Count,Weight,From,To
0,2018-04-01,12,308,A,B
1,2018-04-01,3,475,B,C
2,2018-04-01,23,308,C,D
3,2018-04-01,32,524,D,A
4,2018-04-01,0,308,A,C
5,2018-04-01,23,237,B,D
6,2018-04-01,54,308,B,A
7,2018-04-01,23,237,D,B
8,2018-04-01,18,308,D,C
9,2018-04-01,23,308,C,A
10,2018-04-01,78,475,B,C
11,2018-04-01,67,308,A,B
12,2018-04-01,56,237,D,B
13,2018-04-01,34,308,A,C
14,2018-04-01,27,524,A,D
15,2018-04-01,84,237,D,B
// Create Nodes
USING PERIODIC COMMIT
LOAD CSV WITH HEADERS FROM "file:/1.csv" AS row
CREATE (:Node {Id: row.Id, Desc: row.Desc});
// Create Relationships
USING PERIODIC COMMIT
LOAD CSV WITH HEADERS FROM "file:/2.csv" AS row
MERGE (from:Node {Id: row.From})
MERGE (to:Node {Id: row.To})
MERGE (from)-[rel:RELATED_AS]->(to)
ON CREATE SET rel.SeqNo = toInt(row.SeqNo),
rel.Date = row.flightDate,
rel.Count = toInteger(row.Count),
rel.Weight = toFloat(row.Weight)
This syntax works and creates only 11 relationships, with incoming and outgoing relationships between two nodes. 该语法有效并且仅创建11个关系,两个节点之间具有传入和传出关系。
It is ignoring the additional relationships between AB, BC, AC and DB (2 additional relationships). 它忽略了AB,BC,AC和DB之间的其他关系(2个其他关系)。
How to create the graph with all the 16 relationships? 如何创建具有所有16个关系的图?
Thanks in advance. 提前致谢。
Mel. 梅尔。
Your second query is MERGING the relationship (from)-[rel:RELATED_AS]->(to)
so Cypher is matching that pattern if it exists. 您的第二个查询是合并
(from)-[rel:RELATED_AS]->(to)
以便Cypher匹配该模式(如果存在)。 So the subsequent ones are matched but then the values are never updated because of the ON CREATE
statement. 因此,后续的匹配,但是由于
ON CREATE
语句,因此永远不会更新值。
Since you want to create the relationships every time you could replace your statement with something like the following. 由于您希望每次都创建关系,因此可以将语句替换为以下内容。
USING PERIODIC COMMIT
LOAD CSV WITH HEADERS FROM "file:/2.csv" AS row
MERGE (from:Node {Id: row.From})
MERGE (to:Node {Id: row.To})
CREATE (from)-[rel:RELATED_AS {SeqNo: row.SeqNo, Date: row.flightDate, Count: toInteger(row.Count), Weight: toFloat(row.Weight)}]->(to)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.