# Change tie breaker on aggregation

**URL:** <https://discuss.elastic.co/t/change-tie-breaker-on-aggregation/348434>\
**Category:** Elasticsearch\
**Created:** [December 1, 2023, 1:28pm UTC](https://discuss.elastic.co/t/change-tie-breaker-on-aggregation/348434 "2023-12-01T13:28:30Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Raphael\_Fidelis](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/raphael_fidelis/32/119076_2.png) [@Raphael\_Fidelis](https://discuss.elastic.co/u/Raphael_Fidelis)\
**Post date:** [December 1, 2023, 1:28pm UTC](https://discuss.elastic.co/t/change-tie-breaker-on-aggregation/348434/1 "2023-12-01T13:28:30Z")

</div>

Hello.

As defined in the [terms aggregation docs](https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-bucket-terms-aggregation.html), Elastic uses alphabetical order as a tie-breaker for the aggregation results. However, I wanted to use the order that is returned by the query, i.e.:

```auto
hits: [
   {
      "_score": 267.65305,
      "_source": {
         "id": 1,
         "description": "BBB" 
      },
   },
   {
      "_score": 267.65305,
      "_source": {
         "id": 2,
         "description": "AAA" 
      },
   }
   
]

```

In this case, using an aggregation ordering by the query score, the document with id 2 returns before the one with id 1, however, in case of a score tie, I wanted to keep the query result order. Is it possible?

---

<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 29, 2023, 1:28pm UTC](https://discuss.elastic.co/t/change-tie-breaker-on-aggregation/348434/2 "2023-12-29T13:28:33Z")

</div>

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