Dirk Horsten
Dirk Horsten

Reputation: 3845

How to load ALL the columns from a *.csv into Neo4j nodes

Suppose I need to load a csv file c:\myData.csv

alfa,beta,gamma
0001,1000,thousant
0002,2000,two-K
...

in nodes

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

Is there a way to import ALL the columns into properties without specifying them one by one?

Something like

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.*})

Upvotes: 3

Views: 2358

Answers (2)

iouri
iouri

Reputation: 51

Following worked for me after trying different options, Neo4j 3.3.2:

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

Couple of observations:

  1. CREATE(apple: {appleAllLineProperties}) results in error since Neo4j expects appleAllLineProperties to be a parameter - which also isn't valid in this position.
  2. Neo4j expects the file to be in the following folder

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

Upvotes: 5

Michael Hunger
Michael Hunger

Reputation: 41706

You can use

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

or

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

Upvotes: 2

Related Questions