| 1234567891011121314151617181920212223242526272829303132333435363738394041 | [[java-aggs-metrics-stats]]==== Stats AggregationHere is how you can use{ref}/search-aggregations-metrics-stats-aggregation.html[Stats Aggregation]with Java API.===== Prepare aggregation requestHere is an example on how to create the aggregation request:[source,java]--------------------------------------------------StatsAggregationBuilder aggregation =        AggregationBuilders                .stats("agg")                .field("height");--------------------------------------------------===== Use aggregation responseImport Aggregation definition classes:[source,java]--------------------------------------------------import org.elasticsearch.search.aggregations.metrics.stats.Stats;--------------------------------------------------[source,java]--------------------------------------------------// sr is here your SearchResponse objectStats agg = sr.getAggregations().get("agg");double min = agg.getMin();double max = agg.getMax();double avg = agg.getAvg();double sum = agg.getSum();long count = agg.getCount();--------------------------------------------------
 |