How to create normalizer to make case in sensitive on ElasticSearch

julles

Muhamad Reza Abdul Rohim

Posted on June 6, 2023

How to create normalizer to make case in sensitive on ElasticSearch

By default if you add field on index elasticsearch with keyword data type, you cannot querying or sorting the field with case insensitive, because it is not supported by default, the solution is you can add normalizer like this using kibana:

PUT your_awesome_index_name
{
  "settings": {
    "analysis": {
      "normalizer": {
        "lowercase_normalizer": {
          "type": "custom",
          "filter": ["lowercase"]
        }
      }
    }
  },
  "mappings": {
      "properties": {
        "name": {
          "type": "keyword",
          "normalizer": "lowercase_normalizer"
        }
      }
  }
}
Enter fullscreen mode Exit fullscreen mode

And now you can querying the index data with case insensitive keyword:

GET your_awesome_index_name/_search
{
  "query": {
    "query_string": {
      "default_field": "name.keyword",
      "query": "*reza*"
    }
  }
}
Enter fullscreen mode Exit fullscreen mode
💖 💪 🙅 🚩
julles
Muhamad Reza Abdul Rohim

Posted on June 6, 2023

Join Our Newsletter. No Spam, Only the good stuff.

Sign up to receive the latest update from our blog.

Related