在进行了字段name聚合后,想用filter选取符合10到11岁的人的聚合结果(其中age是整型),但是filter却不起作用,望各位大神能解答一下,多谢!
SearchResponse sr = client.prepareSearch("newtesti").setTypes("newtestd")
.setQuery(QueryBuilders.matchAllQuery())
.addAggregation(AggregationBuilders.terms("Title").field("name"))
.setPostFilter(QueryBuilders.rangeQuery("age").from(10).to(11))
.execute().actionGet();
Terms source = sr.getAggregations().get("Title");
System.out.println(source);
for(Terms.Bucket b:source.getBuckets()){
System.out.println("src_ip:"+b.getKey()+"\tIpCount:"+b.getDocCount());
}
2 个回复
helloes
赞同来自:
所以,根据你的需求,应该用filtered query.
stab - freshman
赞同来自: