# Geo distance stats

**URL:** <https://discuss.elastic.co/t/geo-distance-stats/51809>\
**Category:** Elasticsearch\
**Created:** [June 3, 2016, 3:40pm UTC](https://discuss.elastic.co/t/geo-distance-stats/51809 "2016-06-03T15:40:48Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Andarius](https://avatars.discourse-cdn.com/v4/letter/a/0ea827/32.png) [@Andarius](https://discuss.elastic.co/u/Andarius)\
**Post date:** [June 3, 2016, 3:40pm UTC](https://discuss.elastic.co/t/geo-distance-stats/51809/1 "2016-06-03T15:40:48Z")

</div>

I have the following query that works well:

```auto
{
    "query":{
        "bool": {"filter": [{"match": {"name.raw": name}}, {'match':{'store.raw': store}}]}
    }, 
    "aggs":{
       "products":{
            "terms": {"field": "name.raw"},
            "aggs":{"stats_price": {"stats": { "field": "price"}}}
                }
    },
    "post_filter": {
          "geo_distance":{
                "distance": distance,
                "location": {"lon": lon, "lat": lat}
            }  
    }
}

```

However I fail to find a version of this request where I would have the aggregation done per ring.

So that I would be the result of `aggs :{"stats_price": {"stats": { "field": "price"}}}` per ring within a range `[{"from": 0, "to": 3}, {"from": 0}]` (from 0 would be an aggregation on all the data)

---

<div class="post-metadata">

**Author:** ![Mark\_Harwood](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/mark_harwood/32/10538_2.png) [@Mark\_Harwood](https://discuss.elastic.co/u/Mark_Harwood)\
**Post date:** [June 3, 2016, 4:50pm UTC](https://discuss.elastic.co/t/geo-distance-stats/51809/2 "2016-06-03T16:50:19Z")

</div>

> [@Andarius](#):
>
> However I fail to find a version of this request where I would have the aggregation done per ring.

Did you mean using a geo distance aggregation as opposed to the filter in your example?

> **[Geo Distance Aggregation | Elasticsearch Guide \[2.3\] | Elastic](https://www.elastic.co/guide/en/elasticsearch/reference/2.3/search-aggregations-bucket-geodistance-aggregation.html)**

---

<div class="post-metadata">

**Author:** ![Andarius](https://avatars.discourse-cdn.com/v4/letter/a/0ea827/32.png) [@Andarius](https://discuss.elastic.co/u/Andarius)\
**Post date:** [June 6, 2016, 9:15am UTC](https://discuss.elastic.co/t/geo-distance-stats/51809/3 "2016-06-06T09:15:00Z")

</div>

I still want to use the `post_filter` but I fail to get the `stats` aggregation (using the geo distance aggregation) by bucket.  
To clarify, is it possible to do something like:

```
    "aggs":{
       "rings":{
            "geo_distance":{
                "field": "location",
                "origin": {"lon": lon, "lat": lat},
                "ranges":[{"from": 0, "to": 3}]
                    },
            "aggs": { "price_stats": {"stats" : { "field" : "price" } } }
                }
    },
    "post_filter": {
          "geo_distance":{
                "distance": distance,
                "location": {"lon": lon, "lat": lat}
            }  
    }
```

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [July 5, 2017, 10:45pm UTC](https://discuss.elastic.co/t/geo-distance-stats/51809/4 "2017-07-05T22:45:21Z")

</div>


