简体   繁体   English

从csv在两个节点之间创建具有不同属性的相同类型的多个关系

[英]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.

相关问题 相同类型的多个关系,但在相同的两个节点之间具有不同的属性 - Multiple relationships of the same type but with different properties between the same two nodes 在具有不同属性的节点之间创建相同的关系 - Create same relationships between nodes with different properties 尝试在具有 2 个不同属性名称但其中一些具有相同值的节点之间创建关系 - Trying to create a relationships between nodes with 2 different properties names but some of them have the same value 使用Cypher在Neo4j中的两个节点之间创建相同类型的多个关系 - Creating multiple relationships of the same type between two nodes in Neo4j using Cypher 在具有相同属性的节点之间创建关系 - Creating relationships between nodes with same properties 仅返回两个节点之间的特定关系(来自一种类型的多个) - Return only particular relationships (from multiple of one type) between two nodes neo4j-我们可以在具有相同关系类型但具有不同值的相同节点之间创建多重关系吗? - neo4j - can we create the multiple relationship between same nodes with same relationship type but with different values? 查询具有多个相同类型关系的节点 - Querying for nodes with multiple relationships of the same type 根据两个不同节点之间的关系查询节点 - Querying nodes based on relationships between two different nodes 如何从neo4j中的csv文件导入相同标签的节点之间的关系? - How to import relationships between nodes of the same label from a csv file in neo4j?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM