/**
* 一次计算出count max min avg sum
*/
//统计函数
public void stats(){
SearchResponse response = client.prepareSearch(indexName).setTypes(typeName)
.addAggregation(AggregationBuilders.stats("ageAgg").field("age"))
.get();
//这里的ageAgg字段必须得是数值类型的
Stats ageAgg = response.getAggregations().get("ageAgg");
//总数
long count = ageAgg.getCount();
//最小值
long min = ageAgg.getMin();
//最大值
long max = ageAgg.getMax();
//平均值
long avg = ageAgg.getAvg();
//和
sum = ageAgg.getSum();
}