| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758 | [[java-aggs-bucket-geodistance]]==== Geo Distance AggregationHere is how you can use{ref}/search-aggregations-bucket-geodistance-aggregation.html[Geo Distance Aggregation]with Java API.===== Prepare aggregation requestHere is an example on how to create the aggregation request:[source,java]--------------------------------------------------AggregationBuilder aggregation =        AggregationBuilders                .geoDistance("agg", new GeoPoint(48.84237171118314,2.33320027692004))                .field("address.location")                .unit(DistanceUnit.KILOMETERS)                .addUnboundedTo(3.0)                .addRange(3.0, 10.0)                .addRange(10.0, 500.0);--------------------------------------------------===== Use aggregation responseImport Aggregation definition classes:[source,java]--------------------------------------------------import org.elasticsearch.search.aggregations.bucket.range.Range;--------------------------------------------------[source,java]--------------------------------------------------// sr is here your SearchResponse objectRange agg = sr.getAggregations().get("agg");// For each entryfor (Range.Bucket entry : agg.getBuckets()) {    String key = entry.getKeyAsString();    // key as String    Number from = (Number) entry.getFrom(); // bucket from value    Number to = (Number) entry.getTo();     // bucket to value    long docCount = entry.getDocCount();    // Doc count    logger.info("key [{}], from [{}], to [{}], doc_count [{}]", key, from, to, docCount);}--------------------------------------------------This will basically produce:[source,text]--------------------------------------------------key [*-3.0], from [0.0], to [3.0], doc_count [161]key [3.0-10.0], from [3.0], to [10.0], doc_count [460]key [10.0-500.0], from [10.0], to [500.0], doc_count [4925]--------------------------------------------------
 |