# Sorting not working properly

**URL:** <https://discuss.elastic.co/t/sorting-not-working-properly/199174>\
**Category:** Elasticsearch\
**Created:** [September 12, 2019, 5:33am UTC](https://discuss.elastic.co/t/sorting-not-working-properly/199174 "2019-09-12T05:33:23Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![lucabes](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/lucabes/32/51616_2.png) [@lucabes](https://discuss.elastic.co/u/lucabes)\
**Post date:** [September 12, 2019, 5:33am UTC](https://discuss.elastic.co/t/sorting-not-working-properly/199174/1 "2019-09-12T05:33:23Z")

</div>

Hi  
I have problem with sorting imn ELK 7.3.  
My query: [https://pastebin.com/uK4Ywrec](https://pastebin.com/uK4Ywrec)  
for mapping: [https://pastebin.com/fZ4eyhtm](https://pastebin.com/fZ4eyhtm)  
and index settings [https://pastebin.com/X4SiecP8](https://pastebin.com/X4SiecP8)  
For this query and mapping uI'm getting such order:  
Benny G  
Finn S. Hansen  
Henrik Mårtensson  
Jan Hjort Friderichsen  
ista Nykøbing

And in such case proper order should be:  
Benny G  
Finn S. Hansen  
Henrik Mårtensson  
ista Nykøbing  
Jan Hjort Friderichsen

---

<div class="post-metadata">

**Author:** ![Christian\_Dahlqvist](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/christian_dahlqvist/32/4617_2.png) [@Christian\_Dahlqvist](https://discuss.elastic.co/u/Christian_Dahlqvist)\
**Post date:** [September 12, 2019, 5:38am UTC](https://discuss.elastic.co/t/sorting-not-working-properly/199174/2 "2019-09-12T05:38:22Z")

</div>

What is not working? What is the error? What were you expecting and what are you getting?

---

<div class="post-metadata">

**Author:** ![lucabes](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/lucabes/32/51616_2.png) [@lucabes](https://discuss.elastic.co/u/lucabes)\
**Post date:** [September 12, 2019, 5:42am UTC](https://discuss.elastic.co/t/sorting-not-working-properly/199174/3 "2019-09-12T05:42:57Z")

</div>

Inproper order for pasted query:  
Benny G  
Finn S. Hansen  
Henrik Mårtensson  
Jan Hjort Friderichsen  
ista Nykøbing

And in such case proper order should be:  
Benny G  
Finn S. Hansen  
Henrik Mårtensson  
ista Nykøbing  
Jan Hjort Friderichsen

---

<div class="post-metadata">

**Author:** ![Christian\_Dahlqvist](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/christian_dahlqvist/32/4617_2.png) [@Christian\_Dahlqvist](https://discuss.elastic.co/u/Christian_Dahlqvist)\
**Post date:** [September 12, 2019, 6:01am UTC](https://discuss.elastic.co/t/sorting-not-working-properly/199174/4 "2019-09-12T06:01:06Z")

</div>

Strings are sorted based on lexicographical order. If you look at the [ASCII table](http://www.asciitable.com/) upper and lower case characters are arranged in separate blocks meaning that a lower case character is always considered higher than an upper case character. What you are seeing is therefore expected. To get it sorted the way you want, which is basically a case-insensitive sort, you may need to create a lower cased subfield (or create a custom analyzer for the keyword field) to sort by, although there may be other solutions I am not aware of.

---

<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:** [October 10, 2019, 6:01am UTC](https://discuss.elastic.co/t/sorting-not-working-properly/199174/5 "2019-10-10T06:01:14Z")

</div>

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