I'm new to NEO4J, and am attempting to insert data from a JSON stream into the database. The root element of the JSON stream is an array, each element in the array is an object that contains a key/value, and an array.
sample of JSON stream:
[
{
"access_point":4864834,
"objects": [
{"class_id":10, "name":"iphone", "snr":0.557461},
{"class_id":7, "name":"android", "snr":0.822390},
{"class_id":7, "name":"android", "snr":0.320850},
{"class_id":2, "name":"pc", "snr":0.915604}
]
},
{
"access_point":4864835,
"objects": [
{"class_id":12, "name":"iphone", "snr":0.268736},
{"class_id":10, "name":"android", "snr":0.585927},
{"class_id":7, "name":"android", "snr":0.821383},
{"class_id":2, "name":"pc", "snr":0.254997},
{"class_id":7, "name":"android", "snr":0.326559},
{"class_id":2, "name":"pc", "snr":0.905473}
]
},
Because it is an endless stream, I need to do batch commits as the apoc.load.json will never reach the end of the array.
so far my query looks like:
CALL apoc.periodic.commit("
CALL apoc.load.json('https://raw.githubusercontent.com/jdharri/testjson/master/test.json','$[*]')
YIELD value as accesspoint MERGE(f:Accesspoint {id: accesspoint.access_point, name: accesspoint.access_point})
FOREACH(object IN accesspoint.objects | MERGE (f)-[r:OBSERVED]->(:Object {class_id:object.class_id, name:object.name, access_point_id:accesspoint.access_point}))",
{limit:10, batchSize: 10});
This of course is not referencing a JSON stream, but static JSON in my github.
Is there a way to tell it to persist after n elements in the array?