Thank you for your confirmation.
Although i read the docs I was confused because it does not show a nested apoc call and i ran into weird errors as i mixed the syntax of periodic.commit() and periodic.iterate().
The corrected script is:
(i added the limit and removed the batchsize params)
CALL apoc.periodic.commit(
"CALL apoc.load.json('file:/master_small.json')
YIELD value
MERGE (p:Product {name:value.name})
WITH value, p limit $limit
UNWIND value.categories as cat
MERGE (c:Categorie {name:cat})
MERGE (c)-[r:INHERITS]->(p)",
{limit:100})
Running this code throws this error:
{
"No element found in java.util.Arrays$ArrayItr@224f659a": 1
}
When i run it without the apoc.periodic.commit() it works with no errors though:
CALL apoc.load.json('file:/master_small.json')
YIELD value
MERGE (p:Product {name:value.name})
WITH value, p
UNWIND value.categories as cat
MERGE (c:Categorie {name:cat})
MERGE (c)-[r:INHERITS]->(p)
I want to import a json file with the following structure:
(just with a lot more entries and properties....you get the point)
My goal is to import all products as nodes and categories as nodes.
As you can see the categories are repetetive and hierarchical. So i want no duplicates of the categories.
Without the periodic import and a small json the result is this:
Top level category "Garten & Freizeit" is in the middle and the subcategories are next level nodes and at the end there should be the products ("name" inside the json).
Back to your idea: periodic.iterate()
I tried the following code:
CALL apoc.periodic.iterate(
"CALL apoc.load.json('file:/master_small.json')
YIELD value
MERGE (p:Product {name:value.name})",
"WITH value, p
UNWIND value.categories as cat,
MERGE (c:Categorie {name:cat})
MERGE (c)-[r:INHERITS]->(p)",
{batchSize:100, parallel:true})
I received the following error:
(I am not entirely sure where to split the cypher queries (as iterate() needs two?!)