Specifying the analyzer for a field in the mapping

You can define an analyzer both in the index_analyzer and the search_analyzer member over a field in the mapping process. Also, Elasticsearch allows you to use different analyzers in separate fields.

The following command shows us the mapping for the fields that an analyzer defined:

curl -XPUT localhost:9200/blog -d '{
  "mappings": {
    "article": {
      "properties": {
        "title": {
          "type": "string", "index_analyzer": "simple"
        },
        "content": {
          "type": "string", "index_analyzer": "whitespace", "search_analyzer": "standard"
        }
      }
    }
  }
}'
{"acknowledged":true}

We defined a simple analyzer to the title field, and whitespace analyzer to the content field by the preceding configuration. Also, the search analyzer refers ...

Get Elasticsearch Indexing now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.