分组后聚合不能取值

作者 rongdayouxin | 发布于2018年09月28日 | 阅读数:118

BoolQueryBuilder _BoolQueryBuilder = QueryBuilders.boolQuery();
// RangeQueryBuilder dateTime = QueryBuilders.rangeQuery("smsmtsubmittime");
// dateTime.lte("1538017416280").gte("1538028316280").format("epoch_millis");
// _BoolQueryBuilder.must(dateTime);
QueryStringQueryBuilder _qQueryBuilder1 = QueryBuilders.queryStringQuery("status:0");
QueryStringQueryBuilder _qQueryBuilder2 = QueryBuilders.queryStringQuery("-status:0");
// QueryStringQueryBuilder _qQueryBuilder3 = QueryBuilders.queryStringQuery("0").field("status");
// QueryStringQueryBuilder _qQueryBuilder4 = QueryBuilders.queryStringQuery("0").field("status");
// QueryStringQueryBuilder _qQueryBuilder5 = QueryBuilders.queryStringQuery("0").field("status");
FilterAggregationBuilder _FilterAggregationBuilder1 = AggregationBuilders
.filter("sendSuccessCount", _qQueryBuilder1);
FilterAggregationBuilder _FilterAggregationBuilder2 = AggregationBuilders
.filter("sendFailCount", _qQueryBuilder2);
TermsAggregationBuilder aggregations = AggregationBuilders.terms("cpuserid").field("smsmtuserid").size(100);
aggregations.subAggregation(_FilterAggregationBuilder1).subAggregation(_FilterAggregationBuilder2);
// System.out.println(aggregations.toString());
Map<String, Object> _Map = new HashMap<String, Object>();
SearchResponse scrollResp = this.client.prepareSearch("home_platform_background")
.setTypes("sendallinfo").addSort("id", SortOrder.ASC).setFrom(0).setSize(5).
setQuery(QueryBuilders.matchAllQuery()).addAggregation(aggregations).get();
if (!scrollResp.isTimedOut()) {
Aggregations _Aggregations=scrollResp.getAggregations();
for (Aggregation aggregation : _Aggregations) {
// _log.info("查询的数据="+aggregation.toString());
System.out.println(aggregation.getName());
}
Terms _Terms =_Aggregations.get("cpuserid");
List<? extends Bucket> _BucketS = _Terms.getBuckets();
for (Terms.Bucket bucket : _BucketS) {
_Map.put(bucket.getKey()+"", bucket.getDocCount());
_log.info("查询到的数据:"+bucket.getKeyAsString()+" "+bucket.getDocCount() + "");
InternalAggregations _AggregationTemp =(InternalAggregations) bucket.getAggregations();
_AggregationTemp.asList();
for (Aggregation aggregation : _AggregationTemp) {
System.out.println(aggregation.getName());
System.out.println(aggregation.toString());
}
}
} else {
_log.info(scrollResp.status().getStatus() + "");
}

aggregation 拿到这个值后,不能取出docCount的值
已邀请:

要回复问题请先登录注册