analyzer
Serverless Stack
Only text fields support the analyzer mapping parameter.
The analyzer parameter specifies the analyzer used for text analysis when indexing or searching a text field.
Unless overridden with the search_analyzer mapping parameter, this analyzer is used for both index and search analysis. See Specify an analyzer.
We recommend testing analyzers before using them in production. See Test an analyzer.
The analyzer setting can not be updated on existing fields using the update mapping API.
The search_quote_analyzer setting allows you to specify an analyzer for phrases, this is particularly useful when dealing with disabling stop words for phrase queries.
To disable stop words for phrases a field utilising three analyzer settings will be required:
- An
analyzersetting for indexing all terms including stop words - A
search_analyzersetting for non-phrase queries that will remove stop words - A
search_quote_analyzersetting for phrase queries that will not remove stop words
PUT my-index-000001
{
"settings":{
"analysis":{
"analyzer":{
"my_analyzer":{
"type":"custom",
"tokenizer":"standard",
"filter":[
"lowercase"
]
},
"my_stop_analyzer":{
"type":"custom",
"tokenizer":"standard",
"filter":[
"lowercase",
"english_stop"
]
}
},
"filter":{
"english_stop":{
"type":"stop",
"stopwords":"_english_"
}
}
}
},
"mappings":{
"properties":{
"title": {
"type":"text",
"analyzer":"my_analyzer",
"search_analyzer":"my_stop_analyzer",
"search_quote_analyzer":"my_analyzer"
}
}
}
}
PUT my-index-000001/_doc/1
{
"title":"The Quick Brown Fox"
}
PUT my-index-000001/_doc/2
{
"title":"A Quick Brown Fox"
}
GET my-index-000001/_search
{
"query":{
"query_string":{
"query":"\"the quick brown fox\""
}
}
}
The search_quote_analyzer setting can be updated on existing fields using the update mapping API.
my_analyzeranalyzer which tokens all terms including stop wordsmy_stop_analyzeranalyzer which removes stop wordsanalyzersetting that points to themy_analyzeranalyzer which will be used at index timesearch_analyzersetting that points to themy_stop_analyzerand removes stop words for non-phrase queriessearch_quote_analyzersetting that points to themy_analyzeranalyzer and ensures that stop words are not removed from phrase queries- Since the query is wrapped in quotes it is detected as a phrase query therefore the
search_quote_analyzerkicks in and ensures the stop words are not removed from the query. Themy_analyzeranalyzer will then return the following tokens [the,quick,brown,fox] which will match one of the documents. Meanwhile term queries will be analyzed with themy_stop_analyzeranalyzer which will filter out stop words. So a search for eitherThe quick brown foxorA quick brown foxwill return both documents since both documents contain the following tokens [quick,brown,fox]. Without thesearch_quote_analyzerit would not be possible to do exact matches for phrase queries as the stop words from phrase queries would be removed resulting in both documents matching.