# Lowercase analyzer and aggregation sort

**URL:** <https://discuss.elastic.co/t/lowercase-analyzer-and-aggregation-sort/175657>\
**Category:** Elasticsearch\
**Created:** [April 6, 2019, 12:10am UTC](https://discuss.elastic.co/t/lowercase-analyzer-and-aggregation-sort/175657 "2019-04-06T00:10:06Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Michele\_Caccia](https://avatars.discourse-cdn.com/v4/letter/m/ba9def/32.png) [@Michele\_Caccia](https://discuss.elastic.co/u/Michele_Caccia)\
**Post date:** [April 6, 2019, 12:10am UTC](https://discuss.elastic.co/t/lowercase-analyzer-and-aggregation-sort/175657/1 "2019-04-06T00:10:06Z")

</div>

Hello everybody,  
I think I'm wrong using Elastic custom analyzer (version 1.7 ☹ ).

I use a lowercase analyzer to sort a field in case insensitive way. I found a problem when I analyze the aggregations (I need them to see the list of values). I see aggregation values in lowercase. If I try to query the not analyzed field in the aggregations, I see the difference between upper and lowercase letters but the sort no (first the words that starts with uppercase words and after the lowercase).

There is a way to solve the problem?

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:** [April 6, 2019, 2:50am UTC](https://discuss.elastic.co/t/lowercase-analyzer-and-aggregation-sort/175657/2 "2019-04-06T02:50:34Z")

</div>

Use multi fields. So you will have 2 versions of the same field, one for full text search and another one for aggs.

Note that will be kind of mandatory approach when you will upgrade to 6.x or 7.x.  
And I'd really recommend to upgrade!

---

<div class="post-metadata">

**Author:** ![Michele\_Caccia](https://avatars.discourse-cdn.com/v4/letter/m/ba9def/32.png) [@Michele\_Caccia](https://discuss.elastic.co/u/Michele_Caccia)\
**Post date:** [April 6, 2019, 7:51am UTC](https://discuss.elastic.co/t/lowercase-analyzer-and-aggregation-sort/175657/3 "2019-04-06T07:51:19Z")

</div>

Hi,  
thanks for the reply. The problem is: if I use the second rappresentation of the field for aggs, how can I sort the aggs case insensitive?

---

<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:** [April 6, 2019, 8:10am UTC](https://discuss.elastic.co/t/lowercase-analyzer-and-aggregation-sort/175657/4 "2019-04-06T08:10:58Z")

</div>

Not sure if there's a better option but in modern versions you can add an inner `top_hits` agg and display the first hit of each bucket from which you can retrieve the original value non formatted.

---

<div class="post-metadata">

**Author:** ![Michele\_Caccia](https://avatars.discourse-cdn.com/v4/letter/m/ba9def/32.png) [@Michele\_Caccia](https://discuss.elastic.co/u/Michele_Caccia)\
**Post date:** [April 6, 2019, 6:22pm UTC](https://discuss.elastic.co/t/lowercase-analyzer-and-aggregation-sort/175657/5 "2019-04-06T18:22:11Z")

</div>

Ok,  
with `top_hits` I have the values in correct case form from the aggregation. But the structure is complex and I have to do some stuff backend side.

No other simple method is available for my task? ☹

Thanks

---

<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:** [May 4, 2019, 6:22pm UTC](https://discuss.elastic.co/t/lowercase-analyzer-and-aggregation-sort/175657/6 "2019-05-04T18:22:13Z")

</div>

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