# Need help to simple sort aggregation by other field

**URL:** https://discuss.elastic.co/t/need-help-to-simple-sort-aggregation-by-other-field/237287
**Category:** Elasticsearch
**Created:** [June 16, 2020, 11:51am UTC](https://discuss.elastic.co/t/need-help-to-simple-sort-aggregation-by-other-field/237287 "2020-06-16T11:51:40Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![Uli\_Kasper](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/uli_kasper/32/70454_2.png) [@Uli\_Kasper](https://discuss.elastic.co/u/Uli_Kasper)
#### Post date: [June 16, 2020, 11:51am UTC](https://discuss.elastic.co/t/need-help-to-simple-sort-aggregation-by-other-field/237287/1 "2020-06-16T11:51:40Z")

</div>

Hi,  
my documents in the index have fields named "filter\_color" and "filter\_color\_value".  
"filter\_color" is an interger mapped field containing a number from 10 to 160.  
"filter\_color\_value" is a string field which contains a translated color value e.g. "red".

In my search query I use several aggregations, on "filter\_color" too.  
But they are all naturally sorted by \_count.

I need to sort that aggregation buckets by the field "filter\_color". Tried a lot of things, but nothing worked.

I also tried it with sub-aggregations to get the wanted sort order. What do I have to do?

my aggregation snippet:

```auto
    "aggs" : {
        "filter_color_value" : {
            "terms" : {
                "field" : "filter_color_value"
            }
        }
    }

```

result:

```auto
        "filter_color_value" : {
          "doc_count_error_upper_bound" : 0,
          "sum_other_doc_count" : 1,
          "buckets" : [
            {
              "key" : "weiß",
              "doc_count" : 13
            },
            {
              "key" : "schwarz",
              "doc_count" : 11
            },
            {
              "key" : "blau",
              "doc_count" : 8
            },
            {
              "key" : "transparent",
              "doc_count" : 8
            },
            {
              "key" : "orange",
              "doc_count" : 5
            },
            {
              "key" : "rot",
              "doc_count" : 5
            },
            {
              "key" : "grün",
              "doc_count" : 4
            },
            {
              "key" : "gelb",
              "doc_count" : 3
            },
            {
              "key" : "grau",
              "doc_count" : 3
            },
            {
              "key" : "silber",
              "doc_count" : 2
            }
          ]
        }

```

Thanks for any help!

---

<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 14, 2020, 11:51am UTC](https://discuss.elastic.co/t/need-help-to-simple-sort-aggregation-by-other-field/237287/2 "2020-07-14T11:51:44Z")

</div>

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