在现实开发中难免会遇到一些业务场景,通过聚合得出相应的频次并进行筛选
1.使用 minDocCount 直接上代码,大家可自行根据业务场景更改
//正确答案
SearchRequestBuilder search = transportlient.prepareSearch("bigdata_idx_2").setTypes("captureCompare");
FilterAggregationBuilder sub= AggregationBuilders.filter("channel_longitudeC").filter(QueryBuilders.rangeQuery("fcmp_time").from(startTime).to(endTime));
//分组字段是id,排序由多个字段排序组成
TermsBuilder tb= AggregationBuilders.terms("fcmp_fobj_id").field("fcmp_fobj_id").valueType(Terms.ValueType.STRING).order(Terms.Order.compound(
Terms.Order.aggregation("channel_longitudeC",false)//先按count,降序排
//如果count相等情况下,使用code的和排序
));
//求和字段1
ValueCountBuilder sb= AggregationBuilders.count("channel_longitudeC");
tb.subAggregation(sb).minDocCount(400);//添加到分组聚合请求中
//将分组聚合请求插入到主请求体重
// search.setPostFilter()
search.addAggregation(tb);