I'm using the lib "elasticsearch/elasticsearch": "5.1" with PHP7, ubuntu 16.04
and I'm facing the empty arrays of hits in every query using scroll.
$query = [
'match_all' => (object)[],
];
// Build ElasticSearch Filter parameter (Request Body)
$params = [
'index' => 'my_index',
'scroll' => '30s',
'size' => 50,
'body' => [
'query' => $query
]
];
$scrollId = $this->esClient->search($params)['_scroll_id'];
while (true)
{
$ESResponse = $this->esClient->scroll([
'scroll_id' => $scrollId,
'scroll' => '30s'
]);
error_log('data: ' . json_encode($ESResponse));
if ($ESResponse['timed_out'] === true || $ESResponse['hits']['hits'] === [])
{
break;
}
}
This is the logger data:
stderr : [Mon May 22 15:18:09 2017] data: {"_scroll_id":"DnF1ZXJ5VGhlbkZldGNoBQAAAAAAAADKFlNkdmZfcXZ1UmdXMEk2SmRFVnNqeXcAAAAAAAAAyRZTZHZmX3F2dVJnVzBJNkpkRVZzanl3AAAAAAAAAMsWU2R2Zl9xdnVSZ1cwSTZKZEVWc2p5dwAAAAAAAADMFlNkdmZfcXZ1UmdXMEk2SmRFVnNqeXcAAAAAAAAAzRZTZHZmX3F2dVJnVzBJNkpkRVZzanl3","took":1,"timed_out":false,"terminated_early":false,"_shards":{"total":5,"successful":5,"failed":0},"hits":{"total":2,"max_score":1,"hits":[]}}
ES 5.1.1
ES-PHP "elasticsearch/elasticsearch": "5.1" via composer
PHP7
Ubuntu 16.06
Cli standalone server
I'm pretty sure that I have two records, since the POSTMAN query works ok:
Request
http://127.0.0.1:9200/my_index/_search?size=10
{
"query":{
"match_all":{}
}
}
Response
{
"took": 2,
"timed_out": false,
"_shards": {
"total": 5,
"successful": 5,
"failed": 0
},
"hits": {
"total": 2,
"max_score": 1,
"hits": [
{
"_index": "my_index",
"_type": "email",
"_id": "0100015c3151ea6f-6a784731-48a2-4d6b-bd48-5fbc96a1a899-000000",
"_score": 1,
"_source": {
"subject": "...",
"date": "2017-05-22T18:01:11+00:00",
"message": "...",
"timestamp": "2017-05-22T18:01:11+00:00"
}
},
{
"_index": "lotsa_email_log",
"_type": "email",
"_id": "0100015c312c7135-19bcce6e-1132-4ace-b857-9ad8cd46fe9d-000000",
"_score": 1,
"_source": {
"subject": "....",
"date": "2017-05-22T17:20:15+00:00",
"message": "....",
"timestamp": "2017-05-22T17:20:15+00:00"
}
}
]
}
}
I just replaced some values for privacy.
I'm missing something in my call??
Any help would be great!
There were changes to ES semi-recently about how it handles scrolling. The first scroll request now returns hits as well, so the two hits are inside of the first response:
$scrollId = $this->esClient->search($params)['_scroll_id'];
You'll need to save that entire response, not just the scrollId.
All right, that was the problem.
I added a log to that response and my hits are there.
Thanks for your quick reply ;)
Happy to help! :)
Most helpful comment
There were changes to ES semi-recently about how it handles scrolling. The first scroll request now returns hits as well, so the two hits are inside of the first response:
You'll need to save that entire response, not just the scrollId.