Import CSV
CSV files that comply with the Neo4j import tool’s header format can be imported using the apoc.import.csv
procedure.
This procedure can be used 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.
Usage
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 containing optional configurations.
The procedure support the following config parameters:
name | type | default | description | import tool counterpart |
---|---|---|---|---|
delimiter |
STRING |
, |
delimiter character between columns |
|
arrayDelimiter |
STRING |
; |
delimiter character in arrays |
|
ignoreDuplicateNodes |
BOOLEAN |
false |
for duplicate nodes, only load the first one and skip the rest (true) or fail the import (false) |
|
quotationCharacter |
STRING |
" |
quotation character |
|
stringIds |
BOOLEAN |
true |
treat ids as strings |
|
skipLines |
INTEGER |
1 |
lines to skip (incl. header) |
N/A |
ignoreBlankString |
BOOLEAN |
false |
if true ignore properties with a blank string |
N/A |
ignoreEmptyCellArray |
BOOLEAN |
false |
if true ignore array properties containing a single empty string, like the import tool |
N/A |
compression |
|
|
Allow taking binary data, either not compressed (value: |
N/A |
charset |
STRING |
'UTF-8' |
name of the character extending java.nio.Charset in the currently used JDK. E.g.: |
|
batchSize |
INTEGER |
2000 |
commits and continues after the defined number of rows have been processed |
N/A |
Examples for apoc.import.csv
Loading nodes
Given the following CSV file and procedure call, the database loads two Person
nodes with their name
properties set:
name:STRING John Jane
CALL apoc.import.csv([{fileName: 'file:/persons.csv', labels: ['Person']}], [], {})
Loading nodes and relationships
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.
:ID|name:STRING|speaks:STRING[] 1|John|en,fr 2|Jane|en,de
: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:
-
ID spaces are supported, using the import tool’s syntax.
-
Node labels can be specified with the
:LABEL
field. -
Relationship types can be specified with the
:TYPE
field.