# Case insensitive sorting using normalizer

**URL:** https://discuss.elastic.co/t/case-insensitive-sorting-using-normalizer/214591
**Category:** Elasticsearch
**Tags:** language-clients
**Created:** [January 10, 2020, 11:06am UTC](https://discuss.elastic.co/t/case-insensitive-sorting-using-normalizer/214591 "2020-01-10T11:06:16Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![CesarPozo](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/cesarpozo/32/60608_2.png) [@CesarPozo](https://discuss.elastic.co/u/CesarPozo)
#### Post date: [January 10, 2020, 11:06am UTC](https://discuss.elastic.co/t/case-insensitive-sorting-using-normalizer/214591/1 "2020-01-10T11:06:16Z")

</div>

Hello, I am using elasticsearch 7.5 and NEST client.

I want to sort a query, and as you know, by default does A..Za..z. I want it to be case insensitive.

I am trying to use a normalizer as is explained here:

> [@Case insensitive sort doesn't work](https://discuss.elastic.co/t/case-insensitive-sort-doesnt-work/143192/7):
>
> To sort case-insensitively on a keyword field, you can apply a [normalizer](https://www.elastic.co/guide/en/elasticsearch/reference/current/normalizer.html) to that field. You can think of normalizers as analyzers for keyword fields instead of text fields. So, instead of defining an analyzer in your settings, define a normalizer: PUT /testindex { "settings": { "analysis": { "normalizer": { "case\_insensitive": { "filter": "lowercase" } } } } } Next, apply that normalizer to your keyword field in your mapping: PUT /testindex/\_…

```
PUT /testindex
{
  "settings": {
     "analysis": {
       "normalizer": {
         "case_insensitive": {
            "filter": "lowercase"
         }
        }
       }
     }
}

```

And then I could use it in the mapping:

```
PUT /testindex/_mapping/testmapping
{
  "properties": {
    "Id": {
    "type": "keyword"
    },
    "Name": {
      "type": "text",
      "fields": {
        "keyword": {
          "type": "keyword",
          "normalizer": "case_insensitive"
        }
      }
     }
   }
}

```

The problem it comes when I try to do it on the NEST client:

```
client.Indices.Create("testindex", e => e
                .Settings(s => s
                    .Analysis(a => a
                        .Normalizers(n => n.Custom("case_insensitive",c => c.Filters("lowercase")))))
                .Map(m => m
                    .Properties(p => p
                       .Text(st => st.Name("Name")
                       **.NORMALIZER** )))
            );

```

There is no way to add the normalizer the Name property field.

Any idea?

Thanks a million

---

<div class="post-metadata">

### Author: ![CesarPozo](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/cesarpozo/32/60608_2.png) [@CesarPozo](https://discuss.elastic.co/u/CesarPozo)
#### Post date: [January 13, 2020, 1:05pm UTC](https://discuss.elastic.co/t/case-insensitive-sorting-using-normalizer/214591/2 "2020-01-13T13:05:01Z")

</div>

The question has been answered here by Rob:

> <https://stackoverflow.com/questions/59714787/elasticsearch-7-x-case-insensitive-sorting-using-normalizer/59715143#59715143>

This property is part of keyword type properties as [docs](https://www.elastic.co/guide/en/elasticsearch/reference/current/normalizer.html) say.

> The normalizer property of keyword fields is similar to analyzer except that it guarantees that the analysis chain produces a single token.

Simply changing your prop. to keyword field will allow you to place normalizer

```auto
await client.Indices.CreateAsync("testindex", e => e
    .Settings(s => s
        .Analysis(a => a
            .Normalizers(n => n.Custom("case_insensitive", c => c.Filters("lowercase")))))
    .Map(m => m
        .Properties(p => p
            .Keyword(st => st.Normalizer("case_insensitive").Name("Name"))))
);

```

---

<div class="post-metadata">

### Author: ![Martijn\_Laarman](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/martijn_laarman/32/4410_2.png) [@Martijn\_Laarman](https://discuss.elastic.co/u/Martijn_Laarman)
#### Post date: [January 13, 2020, 1:09pm UTC](https://discuss.elastic.co/t/case-insensitive-sorting-using-normalizer/214591/3 "2020-01-13T13:09:47Z")

</div>

Normalizer is only available on keyword fields, you were nearly there with mapping the provided example to csharp. You still need to introduce the `Fields` for `Name`

```auto
var response2 = Client.Indices.Create("testindex", e => e
	.Settings(s => s
		.Analysis(a => a
			.Normalizers(n => n.Custom("case_insensitive", c => c.Filters("lowercase")))))
	.Map(m => m
		.Properties(p => p
			.Text(st => st
				.Name("Name")
				.Fields(f => f
					.Keyword(kw => kw.Name("Keyword").Normalizer("case_insensitive"))
				)
			)
		)
	)
);

```

You can now sort on `Name.Keyword`.

---

<div class="post-metadata">

### Author: ![CesarPozo](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/cesarpozo/32/60608_2.png) [@CesarPozo](https://discuss.elastic.co/u/CesarPozo)
#### Post date: [January 13, 2020, 2:10pm UTC](https://discuss.elastic.co/t/case-insensitive-sorting-using-normalizer/214591/4 "2020-01-13T14:10:23Z")

</div>

Thanks a million!

---

<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: [February 10, 2020, 2:24pm UTC](https://discuss.elastic.co/t/case-insensitive-sorting-using-normalizer/214591/5 "2020-02-10T14:24:30Z")

</div>

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