来自ElasticSearch

时间:2019-07-29 08:33:19

标签: elasticsearch

今天,我遇到一个错误,即对包含聚合的ElasticSearch的查询未在响应中返回aggregations字段。因此,对于此查询:

{
    "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"
            }
        }
    }
}

我收到如下响应:

{
    "took": 203,
    "timed_out": false,
    "_shards": {
        "total": 255,
        "successful": 254,
        "skipped": 254,
        "failed": 0
    },
    "hits": {
        "total": 0,
        "max_score": 0,
        "hits": []
    }
}

请注意,响应中没有aggregations字段。奇怪的是,这仅发生一次。查询定期运行,响应通常是这样的:

{
  "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" : [ ]
    }
  }
}

因此,即使没有数据,响应中也存在字段 (这是使用它的代码所依赖的内容)。我在ES的文档中找不到对这种行为的任何引用,而且看起来更像是个错误?但是我试图了解这是否是代码应能够处理的预期行为。

0 个答案:

没有答案