geobounds-aggregation.asciidoc 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. [[java-aggs-metrics-geobounds]]
  2. ==== Cardinality Aggregation
  3. Here is how you can use
  4. {ref}/search-aggregations-metrics-geobounds-aggregation.html[Geo Bounds 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. GeoBoundsBuilder aggregation =
  11. AggregationBuilders
  12. .geoBounds("agg")
  13. .field("address.location")
  14. .wrapLongitude(true);
  15. --------------------------------------------------
  16. ===== Use aggregation response
  17. Import Aggregation definition classes:
  18. [source,java]
  19. --------------------------------------------------
  20. import org.elasticsearch.search.aggregations.metrics.geobounds.GeoBounds;
  21. --------------------------------------------------
  22. [source,java]
  23. --------------------------------------------------
  24. // sr is here your SearchResponse object
  25. GeoBounds agg = sr.getAggregations().get("agg");
  26. GeoPoint bottomRight = agg.bottomRight();
  27. GeoPoint topLeft = agg.topLeft();
  28. logger.info("bottomRight {}, topLeft {}", bottomRight, topLeft);
  29. --------------------------------------------------
  30. This will basically produce:
  31. [source,text]
  32. --------------------------------------------------
  33. bottomRight [40.70500764381921, 13.952946866893775], topLeft [53.49603022435221, -4.190029308156676]
  34. --------------------------------------------------