Elasticsearch Query Types: match vs term vs bool
Fast recall
Quick revision
Core answer
Whether you understand the analyzed vs exact-match distinction and can choose the right query type for a given search requirement without over-reaching for match when term is sufficient.
Using match on a keyword field (no-op because keyword is not analyzed) or using term on a text field (misses due to tokenization -- 'New York' becomes two terms, not one).
Explain the filter vs query context distinction in bool queries: queries in filter context do not compute a relevance score and are cached by Elasticsearch, making them faster for non-ranked filtering.
Interview-ready guide
Interview answer
Elasticsearch query types split into two families based on whether they analyze their input before searching. Understanding which family a query belongs to prevents a common class of "why does my query return no results?" bugs.
Full-text queries — analyzed input
matchanalyzes the query string through the same analyzer used to index the field —match: { body: "Spring Boot" }tokenizes to["spring", "boot"]and finds documents containing either or both termsmatch_phraserequires terms to appear adjacent and in order —match_phrase: { body: "spring boot" }only matches documents where "spring" is immediately followed by "boot"- Use
matchontextfields; the analyzer handles stemming and lowercasing automatically
Term-level queries — exact match, no analysis
termfinds documents where a field contains the exact specified value —term: { status: "active" }searches for the literal string "active" with no analysis- Use
termonkeywordfields; usingtermon atextfield often returns nothing because the indexed tokens are lowercase stemmed versions, not the original text termsallows multiple exact values:terms: { status: ["active", "pending"] }— equivalent to SQL'sINclause
bool query — combining conditions
boolis the query used to combine multiple conditions:must(equivalent to AND, contributes to relevance score),should(equivalent to OR, boosts relevance),filter(equivalent to AND, does not affect score, cacheable), andmust_not- Always put filtering conditions (status, date range, user_id) in
filterinstead ofmust— filter clauses are cached by Elasticsearch and don't affect the relevance score, which means subsequent identical filter conditions are resolved from cache
Run queries in Kibana's Dev Tools with "explain": true to see exactly how terms are analyzed and why a document does or does not match.
Elasticsearch Query Types: match vs term vs bool
Direct Answer
Elasticsearch supports two fundamental query categories: full-text queries (match, match_phrase, multi_match) that analyze the query string using the same analyzer as the indexed field, and term-level queries (term, terms, range, exists) that perform exact, unanalyzed lookups. The bool query is a compound query that combines any number of must, should, must_not, and filter clauses to build complex queries.
Common Mistakes & Pitfalls
Using match on a keyword field (no-op because keyword is not analyzed) or using term on a text field (misses due to tokenization -- 'New York' becomes two terms, not one).
Check your understanding
Answer these without looking back at the article.
- What is the difference between query context and filter context in a bool query?
- When would you use match_phrase over match?
- How does field boosting work in a multi_match query?
Related interview prep categories
1Looking for a structured roadmap?
Every module on this page is also part of the full Java backend interview track.