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 to the standard analyzer in the content field.
Now, we will add a document to the blog index as follows:
curl -XPOST localhost:9200/blog/article -d '{ "title": "My boss's...