2014-05-15 06:36:05 -04:00
|
|
|
[[java-aggs-metrics-geobounds]]
|
2016-10-13 07:06:53 -04:00
|
|
|
==== Geo Bounds Aggregation
|
2014-05-15 06:36:05 -04:00
|
|
|
|
|
|
|
Here is how you can use
|
|
|
|
{ref}/search-aggregations-metrics-geobounds-aggregation.html[Geo Bounds Aggregation]
|
|
|
|
with Java API.
|
|
|
|
|
|
|
|
|
|
|
|
===== Prepare aggregation request
|
|
|
|
|
|
|
|
Here is an example on how to create the aggregation request:
|
|
|
|
|
|
|
|
[source,java]
|
|
|
|
--------------------------------------------------
|
2018-01-11 06:59:30 -05:00
|
|
|
GeoBoundsAggregationBuilder aggregation =
|
2016-11-28 11:33:40 -05:00
|
|
|
GeoBoundsAggregationBuilder
|
2014-05-15 06:36:05 -04:00
|
|
|
.geoBounds("agg")
|
|
|
|
.field("address.location")
|
|
|
|
.wrapLongitude(true);
|
|
|
|
--------------------------------------------------
|
|
|
|
|
|
|
|
|
|
|
|
===== Use aggregation response
|
|
|
|
|
|
|
|
Import Aggregation definition classes:
|
|
|
|
|
|
|
|
[source,java]
|
|
|
|
--------------------------------------------------
|
|
|
|
import org.elasticsearch.search.aggregations.metrics.geobounds.GeoBounds;
|
|
|
|
--------------------------------------------------
|
|
|
|
|
|
|
|
[source,java]
|
|
|
|
--------------------------------------------------
|
|
|
|
// sr is here your SearchResponse object
|
|
|
|
GeoBounds agg = sr.getAggregations().get("agg");
|
|
|
|
GeoPoint bottomRight = agg.bottomRight();
|
|
|
|
GeoPoint topLeft = agg.topLeft();
|
|
|
|
logger.info("bottomRight {}, topLeft {}", bottomRight, topLeft);
|
|
|
|
--------------------------------------------------
|
|
|
|
|
|
|
|
This will basically produce:
|
|
|
|
|
|
|
|
[source,text]
|
|
|
|
--------------------------------------------------
|
|
|
|
bottomRight [40.70500764381921, 13.952946866893775], topLeft [53.49603022435221, -4.190029308156676]
|
|
|
|
--------------------------------------------------
|