# Case In-Senstive Sort

**URL:** <https://discuss.elastic.co/t/case-in-senstive-sort/112984>\
**Category:** Elasticsearch\
**Created:** [December 22, 2017, 10:24am UTC](https://discuss.elastic.co/t/case-in-senstive-sort/112984 "2017-12-22T10:24:44Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ahmad\_Bukhari](https://avatars.discourse-cdn.com/v4/letter/a/f9ae1b/32.png) [@Ahmad\_Bukhari](https://discuss.elastic.co/u/Ahmad_Bukhari)\
**Post date:** [December 22, 2017, 10:24am UTC](https://discuss.elastic.co/t/case-in-senstive-sort/112984/1 "2017-12-22T10:24:44Z")

</div>

I've been using elastic searh 5.5.0. And I've noticed that my sorting is not working properly. The results i get from search were not sorted as expected, they were being sorted on the basis of ascii value's.  
Example:  
Actual Output

Book  
Chair  
Table  
board  
cat

Expected Output

Book  
board  
Chair  
cat  
Table

I used analyzers with filter "lowercase" and "asciifolding" But failed to get the desired result.

---

<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:** [December 22, 2017, 10:41am UTC](https://discuss.elastic.co/t/case-in-senstive-sort/112984/2 "2017-12-22T10:41:11Z")

</div>

Could you provide a full recreation script as described in

> [@About the Elasticsearch category](https://discuss.elastic.co/t/about-the-elasticsearch-category/21):
>
> The heart of the free and open Elastic Stack Elasticsearch is a distributed, RESTful search and analytics engine capable of addressing a growing number of use cases. As the heart of the Elastic Stack, it centrally stores your data for lightning fast search, fine‑tuned relevancy, and powerful analytics that scale with ease. warning PLEASE READ THIS SECTION IF IT'S YOUR FIRST POST Some useful links: [elasticsearch reference guide](http://www.elastic.co/guide/en/elasticsearch/reference/current/index.html)[elasticsearch user guide](http://www.elastic.co/guide/en/elasticsearch/guide/current/index.html)[elasticsearch plugins](https://www.elastic.co/guide/en/elasticsearch/plugins/current/index.html)[elasticsearch cl…](https://www.elastic.co/guide/en/elasticsearch/client/index.html)

It will help to better understand what you are doing.  
Please, try to keep the example as simple as possible.

---

<div class="post-metadata">

**Author:** ![Ahmad\_Bukhari](https://avatars.discourse-cdn.com/v4/letter/a/f9ae1b/32.png) [@Ahmad\_Bukhari](https://discuss.elastic.co/u/Ahmad_Bukhari)\
**Post date:** [December 27, 2017, 6:01am UTC](https://discuss.elastic.co/t/case-in-senstive-sort/112984/3 "2017-12-27T06:01:53Z")

</div>

I'm using NEST to implement this and here is the complete Method Implementation:  
public static CreateIndexRequest GetIndexMapping(string index)  
{  
var newIndex = new CreateIndexRequest(index);  
newIndex.Settings = new IndexSettings();  
newIndex.Mappings = new Mappings();  
newIndex.Settings.Analysis = new Analysis();  
newIndex.Settings.Analysis.Analyzers = new Analyzers();  
newIndex.Settings.Analysis.Normalizers = new Normalizers();  
newIndex.Settings.Analysis.Analyzers.Add(Constant.ANALYZER, new CustomAnalyzer() { Tokenizer = "keyword", Filter = new List { "lowercase", "asciifolding" } });  
newIndex.Settings.Analysis.Normalizers.Add("KeywordNormalizer", new CustomNormalizer() {Filter = new List { "lowercase", "asciifolding" } });  
var indexTypes = new string[] { Constant.USER\_TYPE, Constant.GROUP\_TYPE, Constant.CONTACT\_TYPE, Constant.COMPUTER\_TYPE, Constant.OU\_TYPE, Constant.HISTORY\_TYPE };  
foreach (var item in indexTypes)  
{  
var typeMapping = new TypeMapping();  
typeMapping.DynamicTemplates = new DynamicTemplateContainer();  
// text template  
var stringTemplate = new DynamicTemplate();  
stringTemplate.MatchMappingType = "string";  
stringTemplate.Match = "\*";  
var property = new TextProperty() { Type = "text", Analyzer = Constant.ANALYZER, SearchAnalyzer = Constant.ANALYZER };  
property.Fields = new Properties();  
property.Fields.Add("keyword", new KeywordProperty() { Type = "keyword", IgnoreAbove = 1000});

```
                stringTemplate.Mapping = property;
                // long template
                var longTemplate = new DynamicTemplate();
                longTemplate.MatchMappingType = "long";
                longTemplate.Match = "*";
                var longProperty = new NumberProperty() { Type = "long" };
                longProperty.Fields = new Properties();
                longProperty.Fields.Add("keyword", new KeywordProperty() { Type = "keyword", IgnoreAbove = 1000});
                longTemplate.Mapping = longProperty;
                // bool template
                var boolTemplate = new DynamicTemplate();
                boolTemplate.MatchMappingType = "boolean";
                boolTemplate.Match = "*";
                var boolProperty = new BooleanProperty() { Type = "boolean" };
                boolProperty.Fields = new Properties();
                boolProperty.Fields.Add("keyword", new KeywordProperty() { Type = "keyword", IgnoreAbove = 1000});
                boolTemplate.Mapping = boolProperty;
                // binary template

                typeMapping.DynamicTemplates.Add("ImanamiThumbnailTemplate", GetBinaryTemplate("*thumbnail*"));
                typeMapping.DynamicTemplates.Add("ImanamiPhotoTemplate", GetBinaryTemplate("*photo*"));
                typeMapping.DynamicTemplates.Add("ImanamiPictureTemplate", GetBinaryTemplate("*picture*"));
                typeMapping.DynamicTemplates.Add("ImanamiStringTemplate", stringTemplate);
                typeMapping.DynamicTemplates.Add("ImanamiLongTemplate", longTemplate);
                typeMapping.DynamicTemplates.Add("ImanamiBoolTemplate", boolTemplate);
                newIndex.Mappings.Add(item, typeMapping);
            }
            return newIndex;
        }
```

---

<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:** [January 24, 2018, 6:01am UTC](https://discuss.elastic.co/t/case-in-senstive-sort/112984/4 "2018-01-24T06:01:54Z")

</div>

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