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:
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 |
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:
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']}], [], {});
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;
p |
---|
(:Person {name: "John", id: "1"}) |
(:Person {name: "Jane", id: "2"}) |
Nodes and relationships
The following files contain nodes and relationships in CSV format:
:ID|name:STRING|speaks:STRING[]
1|John|en,fr
2|Jane|en,de
: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}
);
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;
path |
---|
(:Person {name: "John", speaks: ["en", "fr"], csv_id: 1})-[:KNOWS {since: 2016}]→(:Person {name: "Jane", speaks: ["en", "de"], csv_id: 2}) |
Was this page helpful?