Bird
0
0

How can you combine a match query with a range filter to find documents where "description" matches "fast car" and "year" is greater than 2015?

hard🚀 Application Q9 of 15
Elasticsearch - Basic Search Queries
How can you combine a match query with a range filter to find documents where "description" matches "fast car" and "year" is greater than 2015?
A{ "query": { "bool": { "must": { "match": { "description": "fast car" } }, "filter": { "range": { "year": { "gt": 2015 } } } } } }
B{ "query": { "match": { "description": "fast car", "year": { "gt": 2015 } } } }
C{ "query": { "range": { "year": { "gt": 2015 } }, "match": { "description": "fast car" } } }
D{ "query": { "match": { "description": "fast car" } }, "filter": { "range": { "year": { "gt": 2015 } } } }
Step-by-Step Solution
Solution:
  1. Step 1: Understand combining queries with bool

    To combine a text match and a numeric range filter, use a bool query with must for match and filter for range.
  2. Step 2: Evaluate options

    { "query": { "bool": { "must": { "match": { "description": "fast car" } }, "filter": { "range": { "year": { "gt": 2015 } } } } } } correctly uses bool with must and filter. { "query": { "match": { "description": "fast car", "year": { "gt": 2015 } } } } incorrectly nests range inside match. { "query": { "range": { "year": { "gt": 2015 } }, "match": { "description": "fast car" } } } incorrectly places two queries side by side. { "query": { "match": { "description": "fast car" } }, "filter": { "range": { "year": { "gt": 2015 } } } } places filter outside query.
  3. Final Answer:

    Use bool query with must match and filter range -> Option A
  4. Quick Check:

    Combine match and range with bool must and filter [OK]
Quick Trick: Use bool query: must for match, filter for range [OK]
Common Mistakes:
MISTAKES
  • Putting range inside match query
  • Placing filter outside query object
  • Using multiple queries without bool

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Elasticsearch Quizzes