Case insensitive sorting using normalizer

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:

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

The question has been answered here by Rob:

This property is part of keyword type properties as docs 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

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"))))
);

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

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.

Thanks a million!

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