# Is case-insensitive sort on keyword aggregation possible ? (ES 6.4)

**URL:** <https://discuss.elastic.co/t/is-case-insensitive-sort-on-keyword-aggregation-possible-es-6-4/153003>\
**Category:** Elasticsearch\
**Created:** [October 18, 2018, 1:05pm UTC](https://discuss.elastic.co/t/is-case-insensitive-sort-on-keyword-aggregation-possible-es-6-4/153003 "2018-10-18T13:05:45Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![mmaury](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/mmaury/32/36671_2.png) [@mmaury](https://discuss.elastic.co/u/mmaury)\
**Post date:** [October 18, 2018, 1:05pm UTC](https://discuss.elastic.co/t/is-case-insensitive-sort-on-keyword-aggregation-possible-es-6-4/153003/1 "2018-10-18T13:05:45Z")

</div>

Hi all !

I want to set up a **case-insensitive sort** order in an **aggregation** , made from a **keyword** field.

Apparently, it wasn't possible with ES 5.2 (see [Keyword type: aggregation case insensitive](https://discuss.elastic.co/t/keyword-type-aggregation-case-insensitive/82682)).

I tried to deal with it on ES 6.4, but without success, using "_icu\_collation\_keyword_" subfield and "_bucket sort aggregation_".

Is it at least possible, in this version (6.4) ?  
Has anyone already implemented it ?  
If the answer is yes, so how ?

Thanks !

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [October 18, 2018, 1:22pm UTC](https://discuss.elastic.co/t/is-case-insensitive-sort-on-keyword-aggregation-possible-es-6-4/153003/2 "2018-10-18T13:22:04Z")

</div>

Would that help? [https://www.elastic.co/guide/en/elasticsearch/reference/current/normalizer.html](https://www.elastic.co/guide/en/elasticsearch/reference/current/normalizer.html)

---

<div class="post-metadata">

**Author:** ![mmaury](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/mmaury/32/36671_2.png) [@mmaury](https://discuss.elastic.co/u/mmaury)\
**Post date:** [October 18, 2018, 1:40pm UTC](https://discuss.elastic.co/t/is-case-insensitive-sort-on-keyword-aggregation-possible-es-6-4/153003/3 "2018-10-18T13:40:19Z")

</div>

Hi @dadoonet !  
I don't think so, because I want my aggregation returns original values, not normalized.  
My values (people names) are international, I want to keep uppercase and accents (that's why I test with the ICU plugin).

---

<div class="post-metadata">

**Author:** ![xeraa](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/xeraa/32/48181_2.png) [@xeraa](https://discuss.elastic.co/u/xeraa)\
**Post date:** [October 18, 2018, 1:59pm UTC](https://discuss.elastic.co/t/is-case-insensitive-sort-on-keyword-aggregation-possible-es-6-4/153003/4 "2018-10-18T13:59:41Z")

</div>

You could add an additional field with the normalizer just for sorting? So you have both the original value and the normalized one.

---

<div class="post-metadata">

**Author:** ![mmaury](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/mmaury/32/36671_2.png) [@mmaury](https://discuss.elastic.co/u/mmaury)\
**Post date:** [October 18, 2018, 2:12pm UTC](https://discuss.elastic.co/t/is-case-insensitive-sort-on-keyword-aggregation-possible-es-6-4/153003/5 "2018-10-18T14:12:59Z")

</div>

Hi @xeraa !  
I tried this with Bucket Sort Aggregation, but ES tells me :

> buckets\_path must reference either a number value or a single value numeric metric aggregation

My aggregation looks like this, where "_creator_" is my keyword field and "_creator.sort_" my "_icu\_collation\_keyword_" subfield :

```
{
  "aggs": {
    "personnes": {
      "terms": {
        "field": "creator",
        "min_doc_count": 1
      },
      "aggs": {
        "creator_sort": {
          "terms": {
            "field": "creator.sort"
          }
        },
        "personnes_bucket_sort": {
          "bucket_sort": {
            "sort": [
              {
                "creator_sort": {
                  "order": "asc"
                }
              }
            ],
            "size": 50
          }
        }
      }
    }
  }
}

```

Maybe I'm doing wrong ?

---

<div class="post-metadata">

**Author:** ![mmaury](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/mmaury/32/36671_2.png) [@mmaury](https://discuss.elastic.co/u/mmaury)\
**Post date:** [October 19, 2018, 9:04am UTC](https://discuss.elastic.co/t/is-case-insensitive-sort-on-keyword-aggregation-possible-es-6-4/153003/6 "2018-10-19T09:04:28Z")

</div>

Hi @elastic !  
Any idea ?

---

<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:** [November 16, 2018, 9:07am UTC](https://discuss.elastic.co/t/is-case-insensitive-sort-on-keyword-aggregation-possible-es-6-4/153003/7 "2018-11-16T09:07:46Z")

</div>

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