# Does specifying the order makes a performance difference for term aggregation?

**URL:** <https://discuss.elastic.co/t/does-specifying-the-order-makes-a-performance-difference-for-term-aggregation/164373>\
**Category:** Elasticsearch\
**Created:** [January 15, 2019, 8:39pm UTC](https://discuss.elastic.co/t/does-specifying-the-order-makes-a-performance-difference-for-term-aggregation/164373 "2019-01-15T20:39:07Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Daniel\_Rodriguez\_a](https://avatars.discourse-cdn.com/v4/letter/d/e19b73/32.png) [@Daniel\_Rodriguez\_a](https://discuss.elastic.co/u/Daniel_Rodriguez_a)\
**Post date:** [January 15, 2019, 8:39pm UTC](https://discuss.elastic.co/t/does-specifying-the-order-makes-a-performance-difference-for-term-aggregation/164373/1 "2019-01-15T20:39:07Z")

</div>

Hello there.

I am aware that ascending sort order is not accurate for term aggregation, but that is not what I want to discuss now.

By default on term aggregation, buckets are sorted descending by doc\_count. I have a function that will specify ascending or descending sort. In order to keep the code smaller, I can just always specify the order and just change a small part of the query based on the order (asc,desc).  
However, I am curious if not specifying the sort order at all, and thus falling back to the default descending order could have an impact on performance. Will it be better ? will ti be worse ?

My query is a very simple term count of one single field

```
    "aggregations": {
      "eventsPerSpace": {
        "terms": {
          shard_size: 200,
          "field": "activeClassroom.keyword",
          "size": 10,
          order: { _count: sort }
        }
      }
    }

```

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:** [February 12, 2019, 8:39pm UTC](https://discuss.elastic.co/t/does-specifying-the-order-makes-a-performance-difference-for-term-aggregation/164373/2 "2019-02-12T20:39:11Z")

</div>

Closed on February 12, 2019, 8:39pm UTC

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