CSV files that comply with the Neo4j import tool’s header format can be imported using the apoc.import.csv
procedure. This procedure is intended to load small- to medium-sized data sets in an online database. For importing larger
data sets, it is recommended to perform a batch import using the (import tool, which loads data in bulk to an offline (initially empty) database.
The parameters of the apoc.import.csv(<nodes>, <relationships>, <config>)
procedure are as follows.
The <nodes>
parameter is a list, where each element is a map defining a source file (fileName
) to be loaded with a set of labels (labels
):
name | description | example |
---|---|---|
|
filename |
|
|
set of labels |
|
The <relationships>
parameter is also a list, where each element is a map defining a source file (fileName
) to be loaded with a given relationship type (type
):
name | description | example |
---|---|---|
|
filename |
|
|
relationship type |
|
The <config>
parameter is a map
name | description | default | import tool counterpart |
---|---|---|---|
|
delimiter character between columns |
|
|
|
delimiter character in arrays |
|
|
|
for duplicate nodes, only load the first one and skip the rest (true) or fail the import (false) |
|
|
|
quotation character |
|
|
|
treat ids as strings |
|
|
|
lines to skip (incl. header) |
|
|
Given the following CSV file and procedure call, the database loads two Person
nodes with their name
properties set:
persons.csv.
name:STRING
John
Jane
CALL apoc.import.csv([{fileName: 'file:/persons.csv', labels: ['Person']}], [], {})
Given the following CSV files and procedure call, the database loads two Person
nodes and a KNOWS
relationship between them (with the value of the since
property set). Note that both the field terminators and the array delimiters are changed from the default value, and the
CSVs use numeric ids.
persons.csv.
:ID|name:STRING|speaks:STRING[]
1|John|en,fr
2|Jane|en,de
knows.csv.
:START_ID|:END_ID|since:INT
1|2|2016
CALL apoc.import.csv(
[{fileName: 'file:/persons.csv', labels: ['Person']}],
[{fileName: 'file:/knows.csv', type: 'KNOWS'}],
{delimiter: '|', arrayDelimiter: ',', stringIds: false}
)
The loader supports advanced features of the import tool:
:LABEL
field.
:TYPE
field.