A compound query in Elasticsearch is a query that combines multiple conditions or queries into one, allowing you to search documents that meet complex criteria.
Click to reveal answer
beginner
Why do compound queries combine conditions?
Compound queries combine conditions to let you search for documents that match multiple rules at once, like finding items that meet several requirements together.
Click to reveal answer
intermediate
Name two common types of compound queries in Elasticsearch.
Two common types are bool queries, which combine must, should, must_not, and filter clauses, and dis_max queries, which pick the best matching query score among several.
Click to reveal answer
intermediate
How does a bool query combine conditions?
A bool query uses logical operators: must means all conditions must match, should means one or more conditions can match, must_not excludes matches, and filter applies conditions without affecting score.
Click to reveal answer
beginner
What is the benefit of combining conditions in a compound query?
Combining conditions helps create precise searches, filtering out unwanted results and focusing on documents that meet all or some specific criteria, improving search relevance.
The must clause expects an array of conditions, but here it is a single object.
Step 2: Verify should clause usage
The should clause is correctly an array, so no error there.
Final Answer:
"must" should be an array, not a single object -> Option C
Quick Check:
Must requires array of conditions [OK]
Hint: Must and should clauses expect arrays [OK]
Common Mistakes:
Using object instead of array for must
Thinking should can't be with must
Misplacing match inside must
5. You want to find documents where the field "category" is "books" and either "author" is "Alice" or "year" is 2020, but exclude those with "status" as "archived". Which bool query correctly combines these conditions?