首页 文章

在Cypher中Neo4J创建关系不会返回任何更改,也不会返回任何行

提问于
浏览
0

我有一个CSV数据集,我正在尝试在我的数据库中已经存在的两种节点类型( CommentPerson )之间 Build 关系 .

这是数据库信息 -

enter image description here

这是我正在尝试构建的当前关系 comment_hasCreator_person 的csv文件 -

enter image description here

问题是 - 无论我尝试哪个Cypher查询,它们都返回相同的东西 - “没有变化,没有行” .

以下是我尝试过的查询的不同变体 -

这是第一个查询 -

// comment_hasCreator_person_0_0.csv
USING PERIODIC COMMIT
LOAD CSV WITH HEADERS FROM "https://dl.dropbox.com/s/qb4occggixmaz9g/comment_hasCreator_person_0_0.csv" AS line
MATCH (comment:Comment { id: toInt(line.Comment.id)}),(person:Person { id: toInt(line.Person.id)})
CREATE (comment)-[:hasCreator]->(person)

我认为这可能没有用,因为我的CSV Headers 最初名为 Comment.idPerson.id . 所以我删除了 . 并尝试了查询,结果相同 -

// comment_hasCreator_person_0_0.csv
USING PERIODIC COMMIT
LOAD CSV WITH HEADERS FROM "https://dl.dropbox.com/s/qb4occggixmaz9g/comment_hasCreator_person_0_0.csv" AS line
MATCH (comment:Comment { id: toInt(line.Commentid)}),(person:Person { id: toInt(line.Personid)})
CREATE (comment)-[:hasCreator]->(person)

当这不起作用时,我跟着this answer并尝试使用 MERGE 而不是 CREATE ,即使它首先不存在't make a difference because the relationships didn' -

USING PERIODIC COMMIT
LOAD CSV WITH HEADERS FROM "https://www.dropbox.com/s/qb4occggixmaz9g/comment_hasCreator_person_0_0.csv?dl=0" AS line
MATCH (comment:Comment { id: toInt(line.Commentid)}),(person:Person { id: toInt(line.Personid)})
MERGE (comment)-[r:hasCreator]->(person)
RETURN comment,r, person

此查询刚刚返回“无行” .

我也尝试了查询的变体,我没有使用 toInt() 函数,但这没有任何区别 .

为了确保节点存在,我从CSV文件中选择了随机单元格值并使用 MATCH 子句来确保数据库中存在相应的 CommentPerson 节点,并且我确实找到了所有节点 .

作为最后一步,我决定在CSV文件的第一行值之间手动创建关系 -

MATCH (c:Comment{id:1236950581249}), (p:Person{id:10995116284808})
CREATE (c)-[r:hasCreator]->(p)
RETURN c,r,p

这工作得很好 -

enter image description here

当我从CSV文件导入关系时,为什么关系不会被创建,我完全不知道 . 我将不胜感激任何帮助 .

2 回答

  • 3

    你的CSV文件有问题 . 其中使用的字段终结符字符是"|",而不是默认的"," . 您可以编辑CSV文件并将字段终结符字符变为",",或使用 LOAD CSV 中的FIELDTERMINATOR选项 .

    尝试将您的查询编辑为以下内容:

    USING PERIODIC COMMIT
    LOAD CSV WITH HEADERS FROM "https://www.dropbox.com/s/qb4occggixmaz9g/comment_hasCreator_person_0_0.csv?dl=0" AS line
    FIELDTERMINATOR '|'
    MATCH (comment:Comment { id: toInt(line.Commentid)}),(person:Person { id: toInt(line.Personid)})
    MERGE (comment)-[r:hasCreator]->(person)
    RETURN comment,r, person
    
  • 0

    你在这里缺少字段终止符,因为它是 | ,而不是 ; .

    你可以尝试一下:

    USING PERIODIC COMMIT LOAD CSV WITH HEADERS FROM "filename" AS LINE FIELDTERMINATOR '|' MERGE (comment:Comment { id: toInt(LINE.Commentid)}) MERGE (person:Person { id: toInt(line.Personid)}) MERGE (comment) - [r:has_creator] -> (person) RETURN comment,r,person

相关问题