我已经像下面的示例csv文件,我想将其导入的Neo4j和创建节点和关系。
"N_ID","Name","Relationship","A_ID","Address"
"N_01","John Doe","resident","A_01","1138 Mapleview Drive"
"N_02","Jane Doe","resident","A_01","1138 Mapleview Drive"
"N_03","Randall L Russo","visitor","A_02","866 Sweetwood Drive"
"N_04","Sam B Haley","resident","A_03","152 Point Street"
"N_01","John Doe","mailing address","A_04",3490 Horizon Circle"
“M能够创建使用下面的代码节点,但我不知道如何根据CSV文件创建关系。
using PERIODIC COMMIT 1000
LOAD CSV WITH HEADERS FROM
‘File://contacts.csv' AS line
CREATE (:Person {ID:line.N_ID, name:line.Name})
我尝试了此操作,但没有用。
CREATE (:Person {N_ID:line.N_ID, Name:line.Name})-[:line.Relationship]-> (:Address {A_ID:line.A_ID, Address:line.Address})
请忍受我是Neo4j的新手。
答案 0 :(得分:2)
安装 apoc plugin 并尝试以下查询:
USING PERIODIC COMMIT 1000
LOAD CSV WITH HEADERS FROM 'file://contacts.csv' AS line
MERGE (p1:Person {N_ID:line.N_ID})
ON CREATE SET p1.Name=line.Name
MERGE (a1:Address {A_ID:line.A_ID})
ON CREATE SET a1.Address=line.Address
WITH a1,p1,line
CALL apoc.merge.relationship(p1,line.Relationship,{},{},a1) YIELD rel
RETURN count(*);