Hi,
We ran into an error where a query to ElasticSearch that included aggregations didn't return the aggregations
field in the response at all. So for a query like this:
{
"size": 0,
"query": {
"bool": {
"filter": [
{
"range": {
"target_status_code": {
"gte": 400
}
}
},
{
"range": {
"timestamp": {
"gte": "2019-07-29T03:47:01",
"lte": "2019-07-29T03:49:01"
}
}
}
]
}
},
"aggs": {
"key": {
"terms": {
"field": "request_key"
}
}
}
}
We got a response like the following
{
"took": 203,
"timed_out": false,
"_shards": {
"total": 255,
"successful": 254,
"skipped": 254,
"failed": 0
},
"hits": {
"total": 0,
"max_score": 0,
"hits": []
}
}
Note that there's not aggregations
field in the response. What is odd is that this only happened twice. The query runs periodically, and the response is usually something like this:
{
"took" : 158,
"timed_out" : false,
"_shards" : {
"total" : 255,
"successful" : 255,
"skipped" : 254,
"failed" : 0
},
"hits" : {
"total" : 0,
"max_score" : 0.0,
"hits" : [ ]
},
"aggregations" : {
"key" : {
"doc_count_error_upper_bound" : 0,
"sum_other_doc_count" : 0,
"buckets" : [ ]
}
}
}
So even though there's no data, the field exists in the response (which is something that the code using it relies on). I couldn't find any reference to a behavior like this in ES' documentation, and it seems more like a bug? But I'm trying to understand if this is expected behavior that the code should be able to handle.
We're on version 6.7.2 of ES, let me know if there's more context I can provide.