2017-05-31 88 views
0

我有一個CSV數據集,通過它我試圖建立我的數據庫中已經存在的兩種節點類型(CommentPerson)之間的關係。Neo4J在Cypher中創建關係不返回任何更改

這是數據庫信息 -

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頭最初命名爲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嘗試,即使它不應該有所作爲因爲關係不存在於第一位 -

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

我m完全不知道爲什麼當我從CSV文件導入關係時不會創建關係。我將不勝感激任何幫助。

回答

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

太感謝你了,我不知道爲什麼,我完全忽略了'|'。特別是因爲我在創建節點期間使用了'fieldterminator'。 –

+0

不客氣! :) –

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