统计索引中某个字段的个数
public class ESTest_Doc_Query {
public static void main(String[] args) throws Exception {
//创建ES客户端
RestHighLevelClient esClient = new RestHighLevelClient(
RestClient.builder(new HttpHost("localhost",9200,"http"))
);
//12、统计个数
SearchRequest request = new SearchRequest();
request.indices("user");
SearchSourceBuilder builder = new SearchSourceBuilder();
//统计年龄在30-40之间的有多少
AggregationBuilder aggregationBuilder = AggregationBuilders.count("ageCount").field("age");
RangeQueryBuilder rangeQueryBuilder = QueryBuilders.rangeQuery("age").from(30,true).to(40,true);
builder.aggregation(aggregationBuilder);
builder.query(rangeQueryBuilder);
request.source(buil