首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Elasticsearch聚合返回always empty buckets [] (elasticsearch版本2.4.1)

Elasticsearch聚合返回always empty buckets [] (elasticsearch版本2.4.1)
EN

Stack Overflow用户
提问于 2017-01-19 04:23:01
回答 1查看 987关注 0票数 0

我有以下代码:

代码语言:javascript
复制
 final String index = ElasticSearchUtils.getIndexNameForExecution(queryId);
        SearchRequestBuilder query = client.prepareSearch(index);
        query.setTypes(indexType.toString());

        query.addAggregation(terms("errors").field("code").size(NUMBER_OF_HITS).order(Terms.Order.count(false)));

        int pageStart = getFrom(page) * size;
        SearchResponse response = query.setFrom(pageStart).setSize(getPageSize(size)).execute().actionGet();

        return response.toString();

回应的一部分是:

代码语言:javascript
复制
{
  "took" : 78,
  "timed_out" : false,
  "_shards" : {
    "total" : 2,
    "successful" : 2,
    "failed" : 0
  },
  "hits" : {
    "total" : 2,
    "max_score" : 1.0,
    "hits" : [ {
      "_index" : "index_587e1e34e4b040c63c49137f",
      "_type" : "ERROR",
      "_id" : "AVmspgsKa7ZIkZu1p32G",
      "_score" : 1.0,
      "_source" : {
        "agent_id" : "{8668b249-9443-e611-87c6-005056aa41d1}",
        "_v" : "1",
        "host" : "RHEL65-X86-DEMO",
        "created_at" : "2017-01-17T13:37:58.496Z",
        "qid" : "587e1e34e4b040c63c49137f",
        "errors" : [ {
          "code" : 769,
          "module" : "FileHashing",
          "function" : "FindFiles"
        } ]
      }
    }, {
      "_index" : "index_587e1e34e4b040c63c49137f",
      "_type" : "ERROR",
      "_id" : "AVmspgsKa7ZIkZu1p32H",
      "_score" : 1.0,
      "_source" : {
        "agent_id" : "{7238f027-fbfc-47cf-85b0-c69838e26a2a}",
        "_v" : "1",
        "host" : "W8-X64-DEMO",
        "created_at" : "2017-01-17T13:37:58.501Z",
        "qid" : "587e1e34e4b040c63c49137f",
        "errors" : [ {
          "code" : 769,
          "module" : "FileHashing",
          "function" : "FindFiles"
        } ]
      }
    } ]
  },
  "aggregations" : {
    "errors" : {
      "doc_count_error_upper_bound" : 0,
      "sum_other_doc_count" : 0,
      "buckets" : [ ]
    }
  }
}

And the result of search execution is:

如您所见,存储桶为空[],聚合不起作用,但任何异常都会抛出。这发生在elasticsearch 2.4.1中,同样的代码也适用于elasticsearch 1.4.1

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2017-01-19 05:56:54

您只需要修复这一行

代码语言:javascript
复制
query.addAggregation(terms("errors").field("errors.code").size(NUMBER_OF_HITS).order(Terms.Order.count(false)));
                                              ^
                                              |
                                          add this
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/41728789

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档