Skip to content

Term vs match query

In the context of Elasticsearch query DSL (Domain Specific Language), the primary distinction between the two lies in text analysis: the term query retrieves data based on the exact value provided, treating the content as a single token, whereas the match query analyzes the input string, performing a tokenization process to break the text down into individual terms before searching.^[600-developer__Elasticsearch.md]

Term Query

The term query is used for exact matching.^[600-developer__Elasticsearch.md] It does not apply the standard analysis process (like tokenization) to the input.^[600-developer__Elasticsearch.md] A common use case is searching for the keyword field type, which is designed for exact matching (e.g., filtering or sorting), or when the user intends to find a specific token as it appears in the Inverted index.^[600-developer__Elasticsearch.md]

For example, searching for the string "iphone 手機" using a term query would look for that specific entire phrase as a single token unit.^[600-developer__Elasticsearch.md]

Match Query

The match query is designed for full-text search scenarios.^[600-developer__Elasticsearch.md] When a query is executed, the search engine first performs word segmentation (analysis) on the input string to break it into individual tokens, and then looks for those tokens in the Inverted index.^[600-developer__Elasticsearch.md] This type of query is typically used with the text field type, which is indexed to support search and relevance scoring.^[600-developer__Elasticsearch.md]

Comparison

The choice between the two depends on whether the search target requires an exact match or a parsed search.

  • term: Treats the input as a single, unanalyzed term (e.g., "iphone 手機").^[600-developer__Elasticsearch.md]
  • match: Performs analysis and tokenization on the input string.^[600-developer__Elasticsearch.md]

Sources

  • 600-developer__Elasticsearch.md