Adding a normalizer for case-insensitive search on keyword field to an active index

I have an active ES index and would like to make searches on it case-insensitive. The indexes are being created dynamically and are actively used. The fields are of "keyword" type. I saw that normalizer is the way to lowercase the search tokens on the index. But I'm unable to close, add normalizer, open the index like for adding an analyzer. Is there a better way to add case-insensitive search to an active cluster?

curl -XPUT localhost:9200/ganesh_index/ -d '
{
  "settings": {
    "analysis": {
      "normalizer": {
        "useLowercase": {
          "type": "custom",
          "filter": [ "lowercase" ]
        }
      }
    }
  },
  "mappings":{
     "ganesh_type":{
        "properties":{
           "title":{
              "normalizer":"useLowercase",
              "type":"keyword"
           }
        }
     }
  }
}'

I tried to use alias, but I'm unable to prepareIndex (post docs to the index using the transport client) to the alias.

I originally asked the question here:

Thanks for any help!

You need to close and open the index in order to change a normalizer/analyzer on an active index.
The lowercasing in your case needs to be applied to all the documents in your index so you also need to reindex your data. The current data that is indexed is not lowercased so changing the normalizer will not change the values that are already indexed.

1 Like

Thanks @jimczi

But I'm unable to add a normalizer on an existing index. (I am able to do this for analyzer, but that doesn't work for keyword fields).

curl -XPUT localhost:9200/ganesh_index/?pretty -d '
> {
>   "settings": {
>     "analysis": {
>       "normalizer": {
>         "useLowercase": {
>           "type": "custom",
>           "filter": [ "lowercase" ]
>         }
>       }
>     }
>   },
>   "mappings":{
>      "ganesh_type":{
>         "properties":{
>            "title":{
>               "normalizer":"useLowercase",
>               "type":"keyword"
>            }
>         }
>      }
>   }
> }'
{
  "error" : {
    "root_cause" : [
      {
        "type" : "index_already_exists_exception",
        "reason" : "index [ganesh_index/mg5TckzaR5KZDE-FphTeDg] already exists",
        "index_uuid" : "mg5TckzaR5KZDE-FphTeDg",
        "index" : "ganesh_index"
      }
    ],
    "type" : "index_already_exists_exception",
    "reason" : "index [ganesh_index/mg5TckzaR5KZDE-FphTeDg] already exists",
    "index_uuid" : "mg5TckzaR5KZDE-FphTeDg",
    "index" : "ganesh_index"
  },
  "status" : 400
}

@gansvv sorry I read your issue too quickly. I though that you were adding a new normalizer to add a new field. You cannot change the normalizer/analyzer that is set in an existing field even if you close the index.
You can only change the search_analyzer but not the analyzer/normalizer that is already set.
You'll need to reindex your data in a new index with the correct mapping upfront. For that you can use _reindex:
https://www.elastic.co/guide/en/elasticsearch/reference/current/docs-reindex.html

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