Neo4j:导入CSV最有效的解决方案是什么?

时间:2018-11-16 09:52:40

标签: csv graph neo4j cypher load

我有以下代码,我需要使用(如果存在)更高效的代码,因为我的csv中有很多行,而Neo4j花费太多时间来添加所有行。

using periodic commit 1000
load csv with headers from "file:///registry_office.csv" as f 
 fieldterminator "|" 
 WITH f AS a
WHERE NOT a.JobName IS NULL and NOT a.JobCode IS NULL and NOT 
 a.JobDescription IS NULL and NOT a.JobLongDescription IS NULL 
 AND NOT a.Long_Description IS NULL AND NOT a.Position IS NULL 
 AND NOT a.birthDate IS NULL AND NOT a.startWorkingDate IS NULL
merge (b:Job{Name:a.JobName, Code:a.JobCode, Job:a.JobDescription, 
 JobLongDescription:a.JobLongDescription})
merge (c:Person{PersonName:a.PersonName, PersonSurname:a.PersonSurname, 
 CF:a.CF, birthDate:a.birthDate, address:a.address, age:a.age, 
 married:a.married, birthPlace:a.a.birthPlace})
merge (b)<-[:RELATED_TO{startWorkingDate:a.startWorkingDate, 
 JobPosition:a.Position}]-(c) 
return *;

您对我有什么建议吗?

1 个答案:

答案 0 :(得分:1)

import tool通常比LOAD CSV快得多。

但是,您的查询建议每个csv行以模式(b)<-(c)结尾,因此您需要对此csv进行一些预处理...首先过滤空值,然后拆分分为3个csv(2个用于节点,1个用于关系)。

为此,您有3个主要选项:

  • Excel -不适用于大型CSV
  • CLI工具-类似csvkit
  • 程序-如果您对Python或JavaScript没问题,则可以在20m左右完成此操作。