The match query is the standard full-text query in Elasticsearch. You give it a field and some text, Elasticsearch analyzes the text with the field's analyzer, and it returns documents that contain any of the resulting terms, ranked by relevance. This guide shows how to use the elasticsearch match query with options such as operator, minimum_should_match and fuzziness.
The examples run on Elasticsearch 8.x and 9.x.
Assume an index articles with a title field of type text.
The query text is analyzed into the terms elasticsearch and search. By default a document matches when it contains at least one of them, so documents 1 and 2 are returned. Document 2 has both terms and gets the higher score, because BM25 rewards documents that match more terms and rarer terms.
The match query runs the query string through the same analyzer as the field (unless you set analyzer in the query). That is why Elasticsearch, ELASTICSEARCH and elasticsearch all match: the standard analyzer lowercases both indexed text and queries.
This also means match is the wrong tool for exact values. On a keyword field, match does not analyze and behaves like an exact term lookup. On a text field, use match for words and use a term query on a keyword subfield for exact strings.
By default the terms are combined with or. Set operator to and to require every term.
Now only document 2 matches. Use and when precision matters, and keep or when you prefer recall and rely on scoring to put the best hits first.
For a middle ground, require a number or percentage of the terms.
With four terms, 75 percent means at least three must be present. This tolerates one missing word, which suits long natural-language queries.
Add fuzziness to match terms within a small edit distance.
AUTO picks the allowed number of edits from the term length. Short terms get no or few edits, longer terms get up to two. Fuzzy queries cost more than plain ones, so use them when typo tolerance is worth it. You can also set prefix_length so the first characters must match exactly, which makes the query faster.
| Query | Use it when |
|---|---|
match_phrase | Words must appear together in order |
multi_match | You search several fields at once |
match_all | You want every document |
match_bool_prefix | You search as the user types |
term | You need an exact value without analysis |
Pick match_phrase for names and quoted phrases, and multi_match when the same text should search title, body and tags with different boosts.
Each hit contains _score and _source. Add "explain": true to see why a score was assigned, and use the analyze API on the field if a document you expected is missing. The cause is usually the analyzer, for example the field is a keyword, or a stop word was removed.
Not on analyzed text fields with the default analyzer, because tokens are lowercased. On keyword fields it is case sensitive.
match analyzes the query text and is meant for text fields. term does not analyze the value and is meant for exact values on keyword, numeric and date fields.
The default operator is or. Set operator to and or use minimum_should_match to require more terms.
Use multi_match with a fields list, or a bool query with several match clauses.
The match query analyzes your text and finds documents with any of the terms by default. Control precision with operator and minimum_should_match, tolerate typos with fuzziness, and switch to match_phrase, multi_match or term when the requirement is different.