OpenSearch/docs/reference/mapping/params/search-analyzer.asciidoc

83 lines
2.1 KiB
Plaintext
Raw Normal View History

[[search-analyzer]]
=== `search_analyzer`
Usually, the same <<analyzer,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 <<analysis-edgengram-tokenizer,`edge_ngram`>>
tokenizer for autocomplete.
By default, queries will use the `analyzer` defined in the field mapping, but
this can be overridden with the `search_analyzer` setting:
[source,js]
--------------------------------------------------
Update the default for include_type_name to false. (#37285) * Default include_type_name to false for get and put mappings. * Default include_type_name to false for get field mappings. * Add a constant for the default include_type_name value. * Default include_type_name to false for get and put index templates. * Default include_type_name to false for create index. * Update create index calls in REST documentation to use include_type_name=true. * Some minor clean-ups around the get index API. * In REST tests, use include_type_name=true by default for index creation. * Make sure to use 'expression == false'. * Clarify the different IndexTemplateMetaData toXContent methods. * Fix FullClusterRestartIT#testSnapshotRestore. * Fix the ml_anomalies_default_mappings test. * Fix GetFieldMappingsResponseTests and GetIndexTemplateResponseTests. We make sure to specify include_type_name=true during xContent parsing, so we continue to test the legacy typed responses. XContent generation for the typeless responses is currently only covered by REST tests, but we will be adding unit test coverage for these as we implement each typeless API in the Java HLRC. This commit also refactors GetMappingsResponse to follow the same appraoch as the other mappings-related responses, where we read include_type_name out of the xContent params, instead of creating a second toXContent method. This gives better consistency in the response parsing code. * Fix more REST tests. * Improve some wording in the create index documentation. * Add a note about types removal in the create index docs. * Fix SmokeTestMonitoringWithSecurityIT#testHTTPExporterWithSSL. * Make sure to mention include_type_name in the REST docs for affected APIs. * Make sure to use 'expression == false' in FullClusterRestartIT. * Mention include_type_name in the REST templates docs.
2019-01-14 16:08:01 -05:00
PUT my_index?include_type_name=true
{
"settings": {
"analysis": {
"filter": {
"autocomplete_filter": {
"type": "edge_ngram",
"min_gram": 1,
"max_gram": 20
}
},
"analyzer": {
"autocomplete": { <1>
"type": "custom",
"tokenizer": "standard",
"filter": [
"lowercase",
"autocomplete_filter"
]
}
}
}
},
"mappings": {
"_doc": {
"properties": {
"text": {
2016-03-18 12:01:27 -04:00
"type": "text",
"analyzer": "autocomplete", <2>
"search_analyzer": "standard" <2>
}
}
}
}
}
PUT my_index/_doc/1
{
"text": "Quick Brown Fox" <3>
}
GET my_index/_search
{
"query": {
"match": {
"text": {
"query": "Quick Br", <4>
"operator": "and"
}
}
}
}
--------------------------------------------------
// CONSOLE
<1> Analysis settings to define the custom `autocomplete` analyzer.
<2> The `text` field uses the `autocomplete` analyzer at index time, but the `standard` analyzer at search time.
<3> This field is indexed as the terms: [ `q`, `qu`, `qui`, `quic`, `quick`, `b`, `br`, `bro`, `brow`, `brown`, `f`, `fo`, `fox` ]
<4> The query searches for both of these terms: [ `quick`, `br` ]
See {defguide}/_index_time_search_as_you_type.html[Index time search-as-you-
type] for a full explanation of this example.
TIP: The `search_analyzer` setting can be updated on existing fields
using the <<indices-put-mapping,PUT mapping API>>.