Challenge - 5 Problems
Compound Query Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate2:00remaining
Output of a bool query with must and filter
What documents will this Elasticsearch bool query return?
{
"query": {
"bool": {
"must": [
{ "match": { "title": "apple" } }
],
"filter": [
{ "term": { "status": "published" } }
]
}
}
}Elasticsearch
{
"query": {
"bool": {
"must": [
{ "match": { "title": "apple" } }
],
"filter": [
{ "term": { "status": "published" } }
]
}
}
}Attempts:
2 left
💡 Hint
Remember that 'must' means conditions that must match, and 'filter' also restricts results but does not affect scoring.
✗ Incorrect
The bool query combines conditions so that documents must match all 'must' clauses and also satisfy all 'filter' clauses. Here, documents must have 'apple' in the title and have status 'published'.
🧠 Conceptual
intermediate1:30remaining
Why use must and should together in a bool query?
In Elasticsearch, why would you combine
must and should clauses inside a bool query?Attempts:
2 left
💡 Hint
Think about how must and should affect matching and scoring.
✗ Incorrect
The must clauses are mandatory conditions, while should clauses are optional but increase the relevance score if matched. This combination allows filtering with must and boosting with should.
❓ Predict Output
advanced2:00remaining
Documents returned by a bool query with must_not
What documents will this Elasticsearch bool query return?
{
"query": {
"bool": {
"must": [
{ "match_all": {} }
],
"must_not": [
{ "term": { "category": "sports" } }
]
}
}
}Elasticsearch
{
"query": {
"bool": {
"must": [
{ "match_all": {} }
],
"must_not": [
{ "term": { "category": "sports" } }
]
}
}
}Attempts:
2 left
💡 Hint
must_not excludes documents matching its clauses.
✗ Incorrect
The must clause matches all documents, but must_not excludes those with category 'sports', so the result is all documents except sports category.
🔧 Debug
advanced1:30remaining
Identify the error in this compound query
What error will this Elasticsearch query cause?
{
"query": {
"bool": {
"must": {
"match": { "title": "banana" }
},
"filter": [
{ "term": { "status": "active" } }
]
}
}
}Elasticsearch
{
"query": {
"bool": {
"must": {
"match": { "title": "banana" }
},
"filter": [
{ "term": { "status": "active" } }
]
}
}
}Attempts:
2 left
💡 Hint
Check if must accepts a single object or an array.
✗ Incorrect
The must clause can accept either a single query object or an array of queries. Here it is a single match query, which is valid.
🧠 Conceptual
expert2:30remaining
Why combine multiple conditions in a compound query?
Why do Elasticsearch compound queries combine multiple conditions instead of using a single condition?
Attempts:
2 left
💡 Hint
Think about how combining conditions affects search results.
✗ Incorrect
Compound queries let you combine must, should, filter, and must_not clauses to control which documents match and how they are scored, enabling precise and flexible search.