Book Image

ElasticSearch Blueprints

Book Image

ElasticSearch Blueprints

Overview of this book

Table of Contents (15 chapters)
Elasticsearch Blueprints
Credits
About the Author
About the Reviewer
www.PacktPub.com
Preface
Index

A case-insensitive search


When we conduct a search, the search has to be case insensitive. This means that even if the user searches with capital letters in keywords, his/her search should avoid the casing of the characters and match keywords with any case. In short, the following should happen while indexing and searching:

 [ "ElasticSearch" , "elasticSearch" ] => "elasticsearch"

To enable a case-insensitive search, we need to design our analyzers accordingly. Once the analyzer is made, we need to simply apply it to the fields in the mapping. Let's see how we can achieve this:

  1. First, we need to create the analyzer:

    curl -X PUT "http://localhost:9200/news" -d '{
      "analysis": {
        "analyzer": {
          "lowercase": {
            "type": "custom",
            "tokenizer": "standard",
            "filter": [
              "lowercase"
            ]
          }
        }
      }
    }'
  2. Then, we need to apply the analyzer to the required field:

    curl -X PUT "http://localhost:9200/news/public/_mapping" -d '{
      "public": {
        "properties...