Ravi Teja Muddada
Ravi Teja Muddada

Reputation: 381

Default Normalizer of elasticsearch that can be applied to all keyword fileds without explicitly mapping

I have created a custom normalizer and custom analyzer with the name 'default' as part of my index template. I can see default analyzer is getting applied to all the fields automatically but the normalizer is not.

Is there any other way that i can achieve this default normalizer getting applied to all the fields ?

My end goal is to search over a field of type keyword in a case insensitive manner using the normalizer

PS: My custom analyzer with name default makes all the fields as keyword.

My settings:

        settings : {
           "index" : {
            "analysis" :{
              "normalizer": {
                "default" : {
                 "type": "custom", 
                 "char_filter":[], 
                 "filter" : ["lowercase"]
             }
    }, 
    
    "analyzer":{
     "default":
     {
    "type":"keyword"
     }
    }
   }
  }
}

Upvotes: 0

Views: 1669

Answers (1)

Val
Val

Reputation: 217254

It would be much easier to leverage dynamic templates to achieve what you want. Simply create your mapping as follows:

PUT my-index
{
  "settings": {
     ...
  },
  "mappings": {
    "dynamic_templates": [
      {
        "strings": {
          "match_mapping_type": "string",
          "mapping": {
            "type": "keyword",
            "ignore_above": 256,
            "normalizer": "default"
          }
        }
      }
    ]
  }
}

That way, every field that is a string will be mapped as a keyword that uses the default normalizer (it doesn't have to be named that way, though)

Upvotes: 1

Related Questions