导入csv时,是否可以在Name节点上拥有多列信息?例如,Name是John Doe,Company,Position是Sales of President,位于California等,在一个节点上。如果是这样,有关如何在上传过程中在cypher中的单个名称节点中合并该信息的任何建议吗?让我们说我有位置,状态,县,电话的信息列。到目前为止,我能够想出的是他/她为公司工作的名称和关系。
LOAD CSV WITH HEADERS FROM 'FILE:///company_name.csv' AS line
MERGE (C:Company {Company: line.Company })
MERGE (N:Name {Name: line.Name })
MERGE (C)<-[:works_for]-(N);
答案 0 :(得分:1)
最佳方法是在使用ON CREATE SET
创建/匹配具有唯一键值的节点后使用ON MATCH SET
和MERGE
。
LOAD CSV WITH HEADERS FROM 'FILE:///company_name.csv' AS line
MERGE (C:Company {Company: line.Company })
MERGE (N:Name {Name: line.Name })
ON CREATE SET
N.Position = line.Position,
N.Location = line.Location,
N.Country = line.Country,
N.Phone = line.Phone
ON MATCH SET
N.Position = line.Position,
N.Location = line.Location,
N.Country = line.Country,
N.Phone = line.Phone
MERGE (C)<-[:works_for]-(N);
或者,您可以在单个节点上设置所有内容,但如果csv文件中有多个行对应于相同的标识,并且您设置的某些值在这些行上不同,那么它将导致多个节点数据库之后。
LOAD CSV WITH HEADERS FROM 'FILE:///company_name.csv' AS line
MERGE (C:Company {Company: line.Company })
MERGE (N:Name {Name: line.Name, Position: line.Position, Location line.Location, Country: line.Country, Phone: line.Phone })
MERGE (C)<-[:works_for]-(N);