Neo4j Cypher - creating nodes and setting labels with LOAD CSV

you can do a workaround - create all nodes and than filter on them and create the desired nodes, than remove those old nodes

LOAD CSV WITH HEADERS FROM 'file:///testfile.csv' AS line
CREATE (tmp:line[1])
WITH tmp
CREATE (x:Person {name: labels(tmp)[0]})
WITH tmp
REMOVE tmp

paste this into http://console.neo4j.org to see example:

LOAD CSV 
WITH HEADERS FROM "http://docs.neo4j.org/chunked/2.1.2/csv/import/persons.csv" AS csvLine
CREATE (p:tmp { id: toInt(csvLine.id), name: csvLine.name })
WITH p
CREATE (pp:Person { name: labels(p)[0]})
WITH p, pp
DELETE p
RETURN pp

bicpence,

First off, this is pretty easy to do with a Java batch import application, and they aren't hard to write. See this batch inserter example. You can use opencsv to read your CSV file.

If you would rather stick with Cypher, and if you have a finite set of labels to work with, then you could do something like this:

USING PERIODIC COMMIT 1000
LOAD CSV WITH HEADERS FROM 'file:///testfile.csv' AS LINE
CREATE (n:load {lab:line.label, prop:line.prop});

CREATE INDEX ON :load(lab);

MATCH (n:load {lab:'label1'})
SET n:label1
REMOVE n:load
REMOVE n.lab;

MATCH (n:load {lab:'label2'})
SET n:label2
REMOVE n:load
REMOVE n.lab;

Grace and peace,

Jim


Unfortunately not, parameterized labels are not supported

Chris