上传具有多个关系的csv

时间:2017-05-17 20:13:34

标签: neo4j graph-databases

我正在尝试在除了投资者之外在生态系统中合作的公司列表(具有员工层级)之间建立关系。我的csv中有6列:公司,投资者,客户(J标记为公司,但关系客户),CompanyX(X标记为公司,但为合作伙伴公司的关系),员工(员工)和EmployeeL( L代表层次结构)。

LOAD CSV WITH HEADERS FROM 'FILE:///ecosystem.csv' AS line
MERGE (C:Company {Company: line.Company })
MERGE (I:Investor {Investor: line.Investor })
MERGE (J:Customer {Company: line.Company })
MERGE (X:CompanyX {Company: line.Company })
MERGE (N:Employee {Employee: line.Employee })
MERGE (L:EmployeeL {Employee: line.Employee })
MERGE (C)<-[:works_for]-(N)
MERGE (L)<-[:reports_to]-(N)
MERGE (J)<-[:Customer]-(C)
MERGE (X)<-[:Partners]->(C)
MERGE (C)<-[:Investor]-(I);

我是否过于复杂?我是Cypher的新手,我不确定我是否做得对,上次我上传的内容与此类似,我不得不擦干数据库。另外,如何为J / I / C输入空值,因为并非所有层次结构都是完整的?当存在空值时,我无法上传csv。

1 个答案:

答案 0 :(得分:0)

如果csv中只有三列,我会创建一个这样的查询:

LOAD CSV WITH HEADERS FROM 'FILE:///ecosystem.csv' AS line
MERGE (C:Company {name: line.Company })
MERGE (I:Investor {name: line.Investor })
MERGE (N:Employee {name: line.Employee })
MERGE (C)<-[:Investor]-(I)
MERGE (C)<-[:works_for]-(N)

您应该避免使用:works_for:reports_to的双向指示。请检查此article