extendedstats-aggregation.asciidoc 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. [[java-aggs-metrics-extendedstats]]
  2. ==== Extended Stats Aggregation
  3. Here is how you can use
  4. {ref}/search-aggregations-metrics-extendedstats-aggregation.html[Extended Stats Aggregation]
  5. with Java API.
  6. ===== Prepare aggregation request
  7. Here is an example on how to create the aggregation request:
  8. [source,java]
  9. --------------------------------------------------
  10. MetricsAggregationBuilder aggregation =
  11. AggregationBuilders
  12. .extendedStats("agg")
  13. .field("height");
  14. --------------------------------------------------
  15. ===== Use aggregation response
  16. Import Aggregation definition classes:
  17. [source,java]
  18. --------------------------------------------------
  19. import org.elasticsearch.search.aggregations.metrics.stats.extended.ExtendedStats;
  20. --------------------------------------------------
  21. [source,java]
  22. --------------------------------------------------
  23. // sr is here your SearchResponse object
  24. ExtendedStats agg = sr.getAggregations().get("agg");
  25. double min = agg.getMin();
  26. double max = agg.getMax();
  27. double avg = agg.getAvg();
  28. double sum = agg.getSum();
  29. long count = agg.getCount();
  30. double stdDeviation = agg.getStdDeviation();
  31. double sumOfSquares = agg.getSumOfSquares();
  32. double variance = agg.getVariance();
  33. --------------------------------------------------