Match & match_phrase queries
match is the workhorse full-text query: it analyzes your input the same way the field was indexed, then OR-combines the resulting terms; match_phrase additionally requires those terms adjacent and in order.
Why it matters
These two cover the bulk of real search-bar traffic. match maximizes recall (“any of these words”), while match_phrase enforces exactness (“this exact wording”). Understanding operator, minimum_should_match, and slop lets you dial precision vs recall without resorting to brittle term queries on the wrong field.
How it works
Both run the field’s analyzer on the query string, producing terms looked up in the inverted-index.
| Query | Default combine | Position-aware? | Key knob |
|---|---|---|---|
match | OR (should) | no | operator, minimum_should_match |
match_phrase | all, in order | yes | slop |
match_phrase_prefix | phrase + last term prefix | yes | max_expansions |
operator: "and"— flipsmatchto require every term, raising precision.minimum_should_match: "75%"— keeps OR behavior but demands a fraction of terms match.slop: 2— allows up to 2 position moves, somatch_phrase "quick fox"(slop 1) matches “quick brown fox”.- Scoring —
matchsums per-term BM25;match_phraserequires positions stored in the index (index_optionsmust keep them).
Example
{ "match": { "title": { "query": "wireless noise cancelling",
"operator": "and" } } }
// indexed terms must include all of [wireless, noise, cancelling]
{ "match_phrase": { "title": { "query": "noise cancelling", "slop": 1 } } }
// matches "noise cancelling" and "noise (active) cancelling"
With the default OR match, a doc containing only “wireless” still matches but scores lowest; operator:"and" drops it entirely.
Pitfalls
matchonkeyword— no analysis happens, so it behaves liketerm; mixed-case input then misses.match_phrase_prefixis expensive — the last term expands to up tomax_expansions(default 50) terms per shard; avoid for true autocomplete, use a completion suggester or edge n-grams.- Stopword surprises —
englishanalyzer drops “the”/“of”, somatch_phrase "war of the worlds"matches “war worlds” unless you account for position gaps. - slop is not edit distance — it measures token moves, not character typos; use
fuzzinessonmatchfor typos.