Index analyzers

Index analyzers are specified at indexing time and are used to analyze text fields when indexing a document.

Determining which index analyzer to use

To determine which analyzer to use for a field when a document is indexed, OpenSearch examines the following parameters in order:

  1. The analyzer mapping parameter of the field
  2. The analysis.analyzer.default index setting
  3. The standard analyzer (default)

When specifying an index analyzer, keep in mind that in most cases, specifying an analyzer for each text field in an index works best. Analyzing both the text field (at indexing time) and the query string (at query time) with the same analyzer ensures that the search uses the same terms as those that are stored in the index.

For information about verifying which analyzer is associated with which field, see Verifying analyzer settings.

Specifying an index analyzer for a field

When creating index mappings, you can supply the analyzer parameter for each text field. For example, the following request specifies the simple analyzer for the text_entry field:

  1. PUT testindex
  2. {
  3. "mappings": {
  4. "properties": {
  5. "text_entry": {
  6. "type": "text",
  7. "analyzer": "simple"
  8. }
  9. }
  10. }
  11. }

copy

Specifying a default index analyzer for an index

If you want to use the same analyzer for all text fields in an index, you can specify it in the analysis.analyzer.default setting as follows:

  1. PUT testindex
  2. {
  3. "settings": {
  4. "analysis": {
  5. "analyzer": {
  6. "default": {
  7. "type": "simple"
  8. }
  9. }
  10. }
  11. }
  12. }

copy

If you don’t specify a default analyzer, the standard analyzer is used.