你的浏览器禁用了JavaScript, 请开启后刷新浏览器获得更好的体验!
输入关键字进行搜索
搜索:
发现
分享
文章
活动
登录
提问要多花一点心思哦
分组之后聚合,获取查询结果无法取出doc_count值 TermsAggregationBuilder FilterAggregationBuilder
Elasticsearch
| 作者
rongdayouxin
| 发布于2018年09月28日 | 阅读数:
6322
分享到:
QQ空间
新浪微博
微信
QQ好友
印象笔记
有道云笔记
系统提示:这个人太懒了,什么问题描述都没有写!
没有找到相关结果
已邀请:
与内容相关的链接
提交
2 个回复
rongdayouxin
赞同来自:
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的值
rongdayouxin
赞同来自:
终于试出来了
for (Aggregation aggregation : _AggregationTemp) {
InternalFilter_InternalFilter =(InternalFilter) aggregation;
_log.info("过滤分组"+_InternalFilter.getName()+"="+_InternalFilter.getDocCount()+"");
}
将aggregation强制转化成InternalFilter即可
要回复问题请先
登录
或
注册
发起人
rongdayouxin
活动推荐
Jun
17
搜索客 Meetup 讲师招募(长期有效)
线上
·
6-17 周一
·
进行中
Nov
30
【活动报名】ClickHouse Beijing User Group 第2届 Meetup
北京
·
11-30 周六
·
报名中
相关问题
elasticsearch scroll查询的原理没太懂
query_string查询疑问
请问查询人与人之间合作度,这种聚合查询怎么写呢?
Elasticsearch聚合操作的时间复杂度是O(n)吗?
logstash获取时间的问题
es scroll查询全部数据问题
聚合查询如何优化
Elasticsearch查询时指定分词器
索引某个shard无法恢复的问题
python 获取ES一个小时内的数据统计点击数有一万多,但具体信息只显示10条,怎么解决?
ik分词情况下“中国人民银行”为例,无法命中结果?
问题状态
最新活动:
2018-09-28 13:29
浏览:
6322
关注:
1
人
2 个回复
rongdayouxin
赞同来自:
// 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的值
rongdayouxin
赞同来自:
for (Aggregation aggregation : _AggregationTemp) {
InternalFilter_InternalFilter =(InternalFilter) aggregation;
_log.info("过滤分组"+_InternalFilter.getName()+"="+_InternalFilter.getDocCount()+"");
}
将aggregation强制转化成InternalFilter即可