search_analyzer
Elastic Cloud Serverless projects are autoscaled environments, fully managed by Elastic and available on Elastic Cloud. Availability This functionality is generally available and ready for production usage. Serverless interfaces and procedures might differ from classic Elastic Stack deployments. The Elastic Stack includes Elastic's core products such as Elasticsearch, Kibana, Logstash, and Beats. Availability This functionality is generally available and ready for production usage. Unless stated otherwise on the page, this functionality is available when your Elastic Stack is deployed on Elastic Cloud Hosted, Elastic Cloud Enterprise, Elastic Cloud on Kubernetes, and self-managed environments. This documentation corresponds to the latest patch available for each minor version. If you're not using the latest patch, check the release notes for changes.
Serverless
Generally available
Stack
Generally available
Usually, the same analyzer should be applied at index time and at search time, to ensure that the terms in the query are in the same format as the terms in the inverted index.
Sometimes, though, it can make sense to use a different analyzer at search time, such as when using the edge_ngram tokenizer for autocomplete or when using search-time synonyms.
By default, queries will use the analyzer defined in the field mapping, but this can be overridden with the search_analyzer setting:
PUT my-index-000001{ "settings": { "analysis": { "filter": { "autocomplete_filter": { "type": "edge_ngram", "min_gram": 1, "max_gram": 20 } }, "analyzer": { "autocomplete": { "type": "custom", "tokenizer": "standard", "filter": [ "lowercase", "autocomplete_filter" ] } } } }, "mappings": { "properties": { "text": { "type": "text", "analyzer": "autocomplete", "search_analyzer": "standard" } } } }PUT my-index-000001/_doc/1{ "text": "Quick Brown Fox" }GET my-index-000001/_search{ "query": { "match": { "text": { "query": "Quick Br", "operator": "and" } } } }
- Analysis settings to define the custom
autocompleteanalyzer. - The
textfield uses theautocompleteanalyzer at index time, but thestandardanalyzer at search time. - This field is indexed as the terms: [
q,qu,qui,quic,quick,b,br,bro,brow,brown,f,fo,fox] - The query searches for both of these terms: [
quick,br]
See Index time search-as-you- type for a full explanation of this example.
The search_analyzer setting can be updated on existing fields using the update mapping API. Note, that in order to do so, any existing "analyzer" setting and "type" need to be repeated in the updated field definition.