如何将* .csv中的所有列加载到Neo4j节点中

时间:2015-01-12 09:30:24

标签: csv neo4j load

假设我需要加载csv文件c:\ myData.csv

alfa,beta,gamma
0001,1000,thousant
0002,2000,two-K
...
节点中的

(:myData{alfa:0001,beta:1000,gamma'thousant'})
(:myData{alfa:0002,beta:2000,gamma'two-k'})

有没有办法将所有列导入属性而不逐一指定它们?

这样的东西
LOAD CSV WITH HEADERS FROM 'file:/c:/myData.csv' AS line set line:myData create line
or
LOAD CSV WITH HEADERS FROM 'file:/c:/myData.csv' AS line create (:myData {line.*})

2 个答案:

答案 0 :(得分:2)

在尝试了不同的选项后,以下为我工作,Neo4j 3.3.2:

USING PERIODIC COMMIT 10000
LOAD CSV WITH HEADERS FROM 'file:///apples.csv' AS appleAllLineProperties
CREATE(apple:Apple)
set apple += appleAllLineProperties

观察结果:

  1. CREATE(apple:{appleAllLineProperties})导致错误,因为Neo4j希望 appleAllLineProperties 成为参数 - 在此位置也无效。
  2. Neo4j希望该文件位于以下文件夹中

    C:\ Users \\ AppData \ Roaming \ Neo4j Desktop \ Application \ neo4jDatabases \ database- \ installation-3.3.2 \ import

答案 1 :(得分:1)

您可以使用

LOAD CSV WITH HEADERS FROM 'file:/c:/myData.csv' AS line 
create (:MyData {line})

LOAD CSV WITH HEADERS FROM 'file:/c:/myData.csv' AS line 
MATCH (m:MyData {id:line.id})
SET m += {line}