2017-05-25 129 views
1

嗨節點之間動態關係有一個CSV文件,我想創建節點和關係,同時
即時通訊使用下面的查詢,以創建節點創建的Neo4j從csv文件

using PERIODIC COMMIT 1000 
load csv from "file:///home/gaurav/sharing/dataframe6.txt" as line fieldterminator" " 
MERGE (A :concept{name:line[0]}) 
WITH line, A 
MERGE (B :concept{name:line[1]}) 
WITH line, A, B 
create (A)-[:line[3]]->(B); // This is trouble part 

,但是當我嘗試創建關係然後我得到錯誤

Invalid input '[': expected an identifier character, whitespace, '|', a length specification, a property map or ']' (line 7, column 18 (offset: 218)) 
"create (A)-[:line[3]]->(B);" 

回答

0

關係不能包含方括號作爲它的類型名稱。您正試圖在節點A和B之間創建「行[3]」關係。

2

如果您真的想以動態方式創建關係,則需要使用APOC過程,具體爲apoc.create.relationship

using PERIODIC COMMIT 1000 
load csv from "file:///home/gaurav/sharing/dataframe6.txt" as line fieldterminator" " 
MERGE (A :concept{name:line[0]}) 
WITH line, A 
MERGE (B :concept{name:line[1]}) 
WITH line, A, B 
CALL apoc.create.relationship(A, line[3], {}, B) YIELD rel 
RETURN A,B,rel 
+1

確保在上次WITH中帶上'line'變量。 – InverseFalcon