Case Insensitive search using match query for keyword

Hi,

I have multiple attributes stored in ES with keyword datatype. I was wondering if it is possible to perform a case in-sensitive search using a match query on these keyword fields?

Thanks.

Have a look at the normalizer property. If you add a lowercase normalizer then you should get case insensitive search.

1 Like

Thanks for your reply.

I have a couple of questions:

  1. Does adding a custom normalizer affect storage or query performance?
  2. If I have an index with a lot of keyword fields, can I add the normalizer at any time or do I have to create a new index with the correct mappings and reindex the data?

Thanks

Storage will be the same but you would have to rebuild the index with the new normalizer.

This is the fastest way to do case insensitive search.

You need to recreate the index after changing the normalizer because it'd build a different on disk structure. You may be able to use dynamic templates to automatically configure the normalizer on your index.

Hi,

I had this problem and use of normalizer property solved it, but it caused a new problem. I have highlighting feature in my query along side with case insensitive keyword search. When I included normalizer property in my mapping, highlighting has stopped working. Do you know why?

Hi @nik9000, I was reading through the documentation for keyword datatype, and it says herehttps://www.elastic.co/guide/en/elasticsearch/reference/current/keyword.html that normalizer is an experimental feature and might go away in a future release.

Am I looking at the wrong documentation or it is indeed the case? Is there a more stable way of achieving case insensitive search? Like converting the keyword to a text field and using a custom analyzer?

Thanks

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