Skip to content

Term vs match query types

In Elasticsearch, the term and match queries are the primary mechanisms for retrieving documents, differing fundamentally in how they handle text analysis and search execution.^[600-developer-elasticsearch.md]

match Query

The match query is designed for full-text search scenarios. When a search query is executed, Elasticsearch applies the analyzer to the search string, breaking it down into individual tokens (a process known as word segmentation or tokenization).^[600-developer-elasticsearch.md] It then searches the Inverted index for these tokens.^[600-developer-elasticsearch.md] This behavior is optimized for fields mapped with the text data type, where content needs to be processed for relevance scoring.^[600-developer-elasticsearch.md]

term Query

The term query operates differently by treating the input as an exact, single token without performing any analysis or word segmentation.^[600-developer-elasticsearch.md] For example, a query string like "iphone 手機" would be treated entirely as one specific word rather than being split into "iphone" and "手機".^[600-developer-elasticsearch.md] This query type is typically used for exact searches, such as filtering on fields mapped with the keyword type (which does not use tokenization), IDs, or tags where precision is required.^[600-developer-elasticsearch.md]

Comparison

  • Analysis: match analyzes the input (tokenizes it); term does not.
  • Use Case: match is for searching text content (full-text retrieval); term is for filtering exact data.
  • Field Type: match is suited for text fields; term is suited for keyword fields.

Sources