Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cypher import of CSV with array

Tags:

neo4j

cypher

I am having trouble importing a CSV with an array into neo4j 2.2.0 using Cypher

Having read about the "CSV header format" (http://neo4j.com/docs/stable/import-tool-header-format.html), I created this file:

name:ID,species,images:string[]
1,Tortula muralis,1.jpg;2.jpg;3.jpg
2,Anthoceros agrestis,6.jpg
3,Marchantia polymorpha,4.jpg;5.jpg

I tried:

LOAD CSV WITH HEADERS FROM 'file:/home/hannes/temp/bryo' AS line
CREATE (a:Bryophyte)
SET a=line

The import itself works. I get three new nodes. If I then print all Broyphyte nodes, the property "image" seems to be one string, not an array.

Not enough reputation to post a pic, sorry...

like image 392
Hannes Becher Avatar asked Dec 14 '22 15:12

Hannes Becher


1 Answers

You are mixing up two things.

For the import tool that you refer to, the import works with

bin/neo4j-import --into test.db --nodes bryo.csv

Whereas for LOAD CSV you'd use a normal header and do the conversions in Cypher:

id,species,images
1,Tortula muralis,1.jpg;2.jpg;3.jpg
2,Anthoceros agrestis,6.jpg
3,Marchantia polymorpha,4.jpg;5.jpg

I tried:

LOAD CSV WITH HEADERS FROM 'file:/home/hannes/temp/bryo' AS line
CREATE (a:Bryophyte {id:line.id, name:line.name,
                     images:split(line.images,",")})
like image 160
Michael Hunger Avatar answered Dec 30 '22 21:12

Michael Hunger