I'm doing some tests in order to figure out how to best import data from a CSV file into Neo4J. I have the following data in the Person.csv file (3 headers, Person_ID, Name, and Type):
Person_ID Name Type
HUA001 Jaap Layperson
HUA002 Teems Priest
HUA003 Frank Layperson
I want to import the nodes which are of a particular type (e.g. 'Layperson').
I thought about creating a LOAD CSV command with a WHERE statement (see below), but Neo4J doesn't particularly like that WHERE statement. Any ideas how to get this (or a query with a similar result) working?
LOAD CSV WITH HEADERS FROM 'file:///Person.csv' AS row
WHERE row.Type='Layperson'
CREATE (p:Person:Layperson {ID: row.Person_ID, name: row.Name})
You can use WITH
and WHERE
combined to filter the required rows and pass on the filtered rows to the next query which creates the nodes.
LOAD CSV WITH HEADERS FROM 'file:///Person.csv' AS row
WITH row
WHERE row.Type='Layperson'
CREATE (p:Person:Layperson {ID: row.Person_ID, name: row.Name})