I'm using elasticsearch in my laravel-app and I want to fetch a huge load of data from a third party API. I've read, that I need to use the scroll API provided by elasticsearch but I can't really figure out how to use it correctly. The amount of data is about 2 million records. So how can I fetch it?
Here is what I did so far:
$query = '
{
"_source":[
"Company.*",
"Company.Metadata.*"
],
"query":{
"bool": {
"must": [
{
"match": {
"Company.Metadata.status": "active"
}
}
]
}
},
"size" : 1000
}
';
$curl = curl_init();
curl_setopt($curl, CURLOPT_POST, 1);
curl_setopt($curl, CURLOPT_POSTFIELDS, $query);
curl_setopt($curl, CURLOPT_URL, "http://thirdpartyapidomain.com/_search?scroll=1m");
curl_setopt($curl, CURLOPT_HTTPHEADER, array(
'Content-Type: application/json'
));
curl_setopt($curl, CURLOPT_USERPWD, "user:mypassword");
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
$result = json_decode(curl_exec($curl));
curl_close($curl);
$hits = $result->hits->hits;
return $hits;
This gives me 1000 records and the scroll_id - but what to do next?
Please help!