DEV Community

Cover image for How to create normalizer to make case in sensitive on ElasticSearch
Muhamad Reza Abdul Rohim
Muhamad Reza Abdul Rohim

Posted on

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

Top comments (0)