apoc.import.csv

Procedure APOC Core

apoc.import.csv(nodes, relationships, config) - imports nodes and relationships from the provided CSV files with given labels and types

Signature

apoc.import.csv(nodes :: LIST? OF MAP?, relationships :: LIST? OF MAP?, config :: MAP?) :: (file :: STRING?, source :: STRING?, format :: STRING?, nodes :: INTEGER?, relationships :: INTEGER?, properties :: INTEGER?, time :: INTEGER?, rows :: INTEGER?, batchSize :: INTEGER?, batches :: INTEGER?, done :: BOOLEAN?, data :: STRING?)

Input parameters

Name Type Default

nodes

LIST? OF MAP?

null

relationships

LIST? OF MAP?

null

config

MAP?

null

Config parameters

The procedure support the following config parameters:

Table 1. Config parameters
name type default description import tool counterpart

delimiter

String

,

delimiter character between columns

--delimiter=,

arrayDelimiter

String

;

delimiter character in arrays

--array-delimiter=;

ignoreDuplicateNodes

Boolean

false

for duplicate nodes, only load the first one and skip the rest (true) or fail the import (false)

--ignore-duplicate-nodes=false

quotationCharacter

String

"

quotation character

--quote='"'

stringIds

Boolean

true

treat ids as strings

--id-type=STRING

skipLines

Integer

1

lines to skip (incl. header)

N/A

ignoreBlankString

Boolean

false

if true ignore properties with a blank string

N/A

Output parameters

Name Type

file

STRING?

source

STRING?

format

STRING?

nodes

INTEGER?

relationships

INTEGER?

properties

INTEGER?

time

INTEGER?

rows

INTEGER?

batchSize

INTEGER?

batches

INTEGER?

done

BOOLEAN?

data

STRING?

Usage Examples

This procedure imports CSV files that comply with the Neo4j import tool’s header format.

Nodes

The following file contains two people:

persons.csv
id:ID,name:STRING
1,John
2,Jane

We’ll place this file into the import directory of our Neo4j instance.

We can create two Person nodes with their name properties set, by running the following query:

CALL apoc.import.csv([{fileName: 'file:/persons.csv', labels: ['Person']}], [], {});
Table 2. Results
file source format nodes relationships properties time rows batchSize batches done data

"progress.csv"

"file"

"csv"

2

0

4

7

0

-1

0

TRUE

NULL

We can check what’s been imported by running the following query:

MATCH (p:Person)
RETURN p;
Table 3. Results
p

(:Person {name: "John", id: "1"})

(:Person {name: "Jane", id: "2"})

Nodes and relationships

The following files contain nodes and relationships in CSV format:

people-nodes.csv
:ID|name:STRING|speaks:STRING[]
1|John|en,fr
2|Jane|en,de
knows-rels.csv
:START_ID|:END_ID|since:INT
1|2|2016

We will import two Person nodes and a KNOWS relationship between them (with the value of the since property set). The field terminators and the array delimiters are changed from the default value, and the CSVs use numeric ids.

CALL apoc.import.csv(
  [{fileName: 'file:/people-nodes.csv', labels: ['Person']}],
  [{fileName: 'file:/knows-rels.csv', type: 'KNOWS'}],
  {delimiter: '|', arrayDelimiter: ',', stringIds: false}
);
Table 4. Results
file source format nodes relationships properties time rows batchSize batches done data

"progress.csv"

"file"

"csv"

2

1

7

7

0

-1

0

TRUE

NULL

We can check what’s been imported by running the following query:

MATCH path = (p1:Person)-[:KNOWS]->(p2:Person)
RETURN path;
Table 5. Results
path

(:Person {name: "John", speaks: ["en", "fr"], csv_id: 1})-[:KNOWS {since: 2016}]→(:Person {name: "Jane", speaks: ["en", "de"], csv_id: 2})