neo4j load 1000 json documents using apoc

355 views Asked by At

I'm trying to load json documents into neo4j which has complex structure...I cannot use csv format...

Can someone please tell how to load 1000+ json documents using apoc?

I know how to load one document trying to find how to load in loop the 1000 documents

2

There are 2 answers

0
cybersam On

If you want to import from multiple JSON documents serially, you can do something like this (assuming that urls is passed to the Cypher query as a parameter):

UNWIND $urls AS url
CALL apoc.load.json(url) YIELD value
...

If it makes sense to perform the imports concurrently (e.g., there is no risk of deadlocks -- because different files would not write-lock the same set of relationships or nodes), you could consider using one of the APOC periodic execution procedures.

0
Konstantin Gatilin On

Assuming that your files are in the "import" directory, the following CQL should work:

CALL apoc.load.directory()
YIELD value as files
UNWIND files as file
CALL apoc.periodic.iterate('
    CALL apoc.load.json($file)
    YIELD value as line
', '
    CREATE (pc:SomeNode{type: line.type}) //Process line here
', {batchSize:10000, parallel:true, params: {file: file}})
YIELD batches, total, updateStatistics
RETURN batches, total, updateStatistics