match, term and match_phrase
Three queries that look interchangeable and behave completely differently.
Open this lesson in the learning hubKey points
matchanalyses your query text with the field analyzer, then looks up each resulting term.termperforms no analysis at all, so it only ever finds a term exactly as it was indexed.- That is why a
termquery on a text field with any capital letter usually returns zero hits. match_phraserequires the terms adjacent and in order, using positions from the postings.sloppermits that many token moves, so a slop of 1 allows one word between the two terms.multi_matchspreads one match across fields, with per-field boosts such astitle^3.
Example
# title is mapped as text, so "Spring Boot" indexed as [spring, boot]
GET /articles/_search
{ "query": { "match": { "title": "Spring Boot" } } } # 1 hit
GET /articles/_search
{ "query": { "term": { "title": "Spring Boot" } } } # 0 hits
GET /articles/_search
{ "query": { "term": { "title.keyword": "Spring Boot" } } } # 1 hit
Use match on text fields and term on keyword fields - swapping them fails silently.
This is a reading copy. The full lesson — with the visual explainer, the interactive lab and a Run button for the code — lives in the Elasticsearch Course course, and every lesson in it is listed on the Elasticsearch Course contents page.