Bird
0
0

How can you combine an exists query with a range query to find documents where price exists and is greater than 100?

hard🚀 Application Q9 of 15
Elasticsearch - Basic Search Queries
How can you combine an exists query with a range query to find documents where price exists and is greater than 100?
A{"query": {"range": {"price": {"gt": 100, "exists": true}}}}
B{"query": {"exists": {"field": "price", "gt": 100}}}
C{"query": {"bool": {"should": [{"exists": {"field": "price"}}, {"range": {"price": {"gt": 100}}}]}}}
D{"query": {"bool": {"must": [{"exists": {"field": "price"}}, {"range": {"price": {"gt": 100}}}]}}}
Step-by-Step Solution
Solution:
  1. Step 1: Understand combining queries with bool must

    To require both conditions, use a bool query with must containing both exists and range queries.
  2. Step 2: Analyze each option

    {"query": {"bool": {"must": [{"exists": {"field": "price"}}, {"range": {"price": {"gt": 100}}}]}}} correctly uses bool must with both queries; A and B misuse parameters; D uses should which means either condition, not both.
  3. Final Answer:

    {"query": {"bool": {"must": [{"exists": {"field": "price"}}, {"range": {"price": {"gt": 100}}}]}}} -> Option D
  4. Quick Check:

    Use bool must to combine exists and range queries [OK]
Quick Trick: Combine with bool must for AND logic [OK]
Common Mistakes:
MISTAKES
  • Using should instead of must for AND
  • Adding invalid parameters inside exists or range

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Elasticsearch Quizzes