# Can I aggregate ElasticSearch results by geo\_polygon?

**URL:** <https://discuss.elastic.co/t/can-i-aggregate-elasticsearch-results-by-geo-polygon/2077>\
**Category:** Elasticsearch\
**Created:** [June 6, 2015, 10:06pm UTC](https://discuss.elastic.co/t/can-i-aggregate-elasticsearch-results-by-geo-polygon/2077 "2015-06-06T22:06:21Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![ariutk](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ariutk/32/548_2.png) [@ariutk](https://discuss.elastic.co/u/ariutk)\
**Post date:** [June 6, 2015, 10:06pm UTC](https://discuss.elastic.co/t/can-i-aggregate-elasticsearch-results-by-geo-polygon/2077/1 "2015-06-06T22:06:21Z")

</div>

I have an ElasticSearch query that returns stats about items in a single geo\_polygon (number of matches, averages/totals etc.)

Is it possible to modify the query to send a list of polygons, with the results aggregated by geo\_polygon?

---

<div class="post-metadata">

**Author:** ![colings86](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/colings86/32/44960_2.png) [@colings86](https://discuss.elastic.co/u/colings86)\
**Post date:** [June 8, 2015, 7:42am UTC](https://discuss.elastic.co/t/can-i-aggregate-elasticsearch-results-by-geo-polygon/2077/2 "2015-06-08T07:42:29Z")

</div>

you could use the filters aggregation and specify a geo filter for each of your polygons. Then you could have your statistics (I am assuming you are using aggregations to generate them) as sub-aggregations of this filters aggregation.

See the following for more information on the filters aggregation: [https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-bucket-filters-aggregation.html](https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-bucket-filters-aggregation.html)

---

<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 6, 2017, 12:09am UTC](https://discuss.elastic.co/t/can-i-aggregate-elasticsearch-results-by-geo-polygon/2077/3 "2017-07-06T00:09:03Z")

</div>


