Index and search analysis

Text analysis occurs at two times:

Index time
When a document is indexed, any text field values are analyzed.
Search time

When running a full-text search on a text field, the query string (the text the user is searching for) is analyzed. Search time is also called query time.

For more details on text analysis at search time, refer to Text analysis during search.

The analyzer, or set of analysis rules, used at each time is called the index analyzer or search analyzer respectively.

In most cases, the same analyzer should be used at index and search time. This ensures the values and query strings for a field are changed into the same form of tokens. In turn, this ensures the tokens match as expected during a search.

While less common, it sometimes makes sense to use different analyzers at index and search time. To enable this, Elasticsearch allows you to specify a separate search analyzer.

A separate search analyzer is useful in situations such as:

  • Synonyms: For most use cases, apply synonym rules at either search time (recommended) or index time, rather than in both phases.
  • Avoiding unintended matches: Use different analyzers when applying the same analysis to indexed field values and query strings would produce unexpected or irrelevant matches.

The following example shows how using the same analyzer at index and search time can produce unintended matches.