[英]Elasticsearch aggregation return always empty buckets [] (elasticsearch version 2.4.1)
我有以下代码:
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();
部分响应是:
{ "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中工作
您只需要修复此行
query.addAggregation(terms("errors").field("errors.code").size(NUMBER_OF_HITS).order(Terms.Order.count(false)));
^
|
add this
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.