| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202 | [[specify-analyzer]]=== Specify an analyzer{es} offers a variety of ways to specify built-in or custom analyzers:* By `text` field, index, or query* For <<analysis-index-search-time,index or search time>>[TIP].Keep it simple====The flexibility to specify analyzers at different levels and for different timesis great... _but only when it's needed_.In most cases, a simple approach works best: Specify an analyzer for each`text` field, as outlined in <<specify-index-field-analyzer>>.This approach works well with {es}'s default behavior, letting you use the sameanalyzer for indexing and search. It also lets you quickly see which analyzerapplies to which field using the <<indices-get-mapping,get mapping API>>.If you don't typically create mappings for your indices, you can use<<index-templates,index templates>> to achieve a similar effect.====[[specify-index-time-analyzer]]==== How {es} determines the index analyzer{es} determines which index analyzer to use by checking the following parametersin order:. The <<analyzer,`analyzer`>> mapping parameter for the field.  See <<specify-index-field-analyzer>>.. The `analysis.analyzer.default` index setting.  See <<specify-index-time-default-analyzer>>.If none of these parameters are specified, the<<analysis-standard-analyzer,`standard` analyzer>> is used.[[specify-index-field-analyzer]]==== Specify the analyzer for a fieldWhen mapping an index, you can use the <<analyzer,`analyzer`>> mapping parameterto specify an analyzer for each `text` field.The following <<indices-create-index,create index API>> request sets the`whitespace` analyzer as the analyzer for the `title` field.[source,console]----PUT my-index-000001{  "mappings": {    "properties": {      "title": {        "type": "text",        "analyzer": "whitespace"      }    }  }}----[[specify-index-time-default-analyzer]]==== Specify the default analyzer for an indexIn addition to a field-level analyzer, you can set a fallback analyzer forusing the `analysis.analyzer.default` setting.The following <<indices-create-index,create index API>> request sets the`simple` analyzer as the fallback analyzer for `my-index-000001`.[source,console]----PUT my-index-000001{  "settings": {    "analysis": {      "analyzer": {        "default": {          "type": "simple"        }      }    }  }}----[[specify-search-analyzer]]==== How {es} determines the search analyzer// tag::search-analyzer-warning[][WARNING]====In most cases, specifying a different search analyzer is unnecessary. Doing socould negatively impact relevancy and result in unexpected search results.If you choose to specify a separate search analyzer, we recommend you thoroughly<<test-analyzer,test your analysis configuration>> before deploying inproduction.====// end::search-analyzer-warning[]At search time, {es} determines which analyzer to use by checking the followingparameters in order:. The <<analyzer,`analyzer`>> parameter in the search query.  See <<specify-search-query-analyzer>>.. The <<search-analyzer,`search_analyzer`>> mapping parameter for the field.  See <<specify-search-field-analyzer>>.. The `analysis.analyzer.default_search` index setting.  See <<specify-search-default-analyzer>>.. The <<analyzer,`analyzer`>> mapping parameter for the field.  See <<specify-index-field-analyzer>>.If none of these parameters are specified, the<<analysis-standard-analyzer,`standard` analyzer>> is used.[[specify-search-query-analyzer]]==== Specify the search analyzer for a queryWhen writing a <<full-text-queries,full-text query>>, you can use the `analyzer`parameter to specify a search analyzer. If provided, this overrides any othersearch analyzers.The following <<search-search,search API>> request sets the `stop` analyzer asthe search analyzer for a <<query-dsl-match-query,`match`>> query.[source,console]----GET my-index-000001/_search{  "query": {    "match": {      "message": {        "query": "Quick foxes",        "analyzer": "stop"      }    }  }}----// TEST[s/^/PUT my-index-000001\n/][[specify-search-field-analyzer]]==== Specify the search analyzer for a fieldWhen mapping an index, you can use the <<analyzer,`search_analyzer`>> mappingparameter to specify a search analyzer for each `text` field.If a search analyzer is provided, the index analyzer must also be specifiedusing the `analyzer` parameter.The following <<indices-create-index,create index API>> request sets the`simple` analyzer as the search analyzer for the `title` field.[source,console]----PUT my-index-000001{  "mappings": {    "properties": {      "title": {        "type": "text",        "analyzer": "whitespace",        "search_analyzer": "simple"      }    }  }}----[[specify-search-default-analyzer]]==== Specify the default search analyzer for an indexWhen <<indices-create-index,creating an index>>, you can set a default searchanalyzer using the `analysis.analyzer.default_search` setting.If a search analyzer is provided, a default index analyzer must also bespecified using the `analysis.analyzer.default` setting.The following  <<indices-create-index,create index API>> request sets the`whitespace` analyzer as the default search analyzer for the `my-index-000001` index.[source,console]----PUT my-index-000001{  "settings": {    "analysis": {      "analyzer": {        "default": {          "type": "simple"        },        "default_search": {          "type": "whitespace"        }      }    }  }}----
 |