# How to sort by distance in aggregation?

**URL:** <https://discuss.elastic.co/t/how-to-sort-by-distance-in-aggregation/257391>\
**Category:** Elasticsearch\
**Created:** [December 2, 2020, 4:47pm UTC](https://discuss.elastic.co/t/how-to-sort-by-distance-in-aggregation/257391 "2020-12-02T16:47:34Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![isma-el](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/isma-el/32/80119_2.png) [@isma-el](https://discuss.elastic.co/u/isma-el)\
**Post date:** [December 2, 2020, 4:47pm UTC](https://discuss.elastic.co/t/how-to-sort-by-distance-in-aggregation/257391/1 "2020-12-02T16:47:34Z")

</div>

Hello,

is it possible to sort by geodistance in an aggregation ?  
I can't find a way to achieve this.

I need aggregations to remove duplicates according to multiple terms, bu I need to sort the results by geodistance.

Thanks in advance

---

<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:** [December 30, 2020, 4:47pm UTC](https://discuss.elastic.co/t/how-to-sort-by-distance-in-aggregation/257391/2 "2020-12-30T16:47:41Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
