Challenge - 5 Problems
Nested Query Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate2:00remaining
Output of a nested query filtering by nested field
Given the following Elasticsearch nested query, what is the expected output when searching an index with documents containing nested 'comments' objects?
Assuming the index has documents with nested comments by various authors with different likes, which option best describes the result?
{
"query": {
"nested": {
"path": "comments",
"query": {
"bool": {
"must": [
{ "match": { "comments.author": "alice" } },
{ "range": { "comments.likes": { "gte": 10 } } }
]
}
}
}
}
}Assuming the index has documents with nested comments by various authors with different likes, which option best describes the result?
Attempts:
2 left
💡 Hint
Remember that nested queries match nested objects individually, not across different nested objects.
✗ Incorrect
The nested query filters documents where at least one nested 'comments' object matches both conditions: author is 'alice' and likes are 10 or more. It does not combine conditions across different nested objects.
🧠 Conceptual
intermediate1:30remaining
Understanding the purpose of nested queries
Why do we use nested queries in Elasticsearch when dealing with nested objects instead of regular queries?
Attempts:
2 left
💡 Hint
Think about how nested objects are stored and how queries match them.
✗ Incorrect
Nested queries ensure that conditions apply to the same nested object instance, preserving the relationship between fields inside that object. Regular queries might match fields from different nested objects incorrectly.
🔧 Debug
advanced2:00remaining
Identify the error in this nested query
What error will this Elasticsearch query produce?
Assuming 'comments' is a nested field, what is wrong?
{
"query": {
"nested": {
"path": "comments",
"query": {
"match": {
"author": "bob"
}
}
}
}
}Assuming 'comments' is a nested field, what is wrong?
Attempts:
2 left
💡 Hint
Check the field name used inside the nested query's match clause.
✗ Incorrect
Inside a nested query, the field names must be fully qualified with the nested path prefix. Using just 'author' instead of 'comments.author' causes Elasticsearch to not find the field.
📝 Syntax
advanced2:00remaining
Correct syntax for nested query with inner hits
Which of the following nested queries correctly includes inner hits to return matching nested objects?
Attempts:
2 left
💡 Hint
Check the order and presence of required keys and correct field names.
✗ Incorrect
Option A correctly places 'path', 'query', and 'inner_hits' keys and uses the fully qualified field 'comments.text'. Option A has keys in wrong order (though order is not critical, but inner_hits should be after query), C misses inner_hits, D uses unqualified field 'text'.
🚀 Application
expert3:00remaining
Construct a nested query to find documents with nested comments by 'eve' having likes between 5 and 15
You want to find documents where at least one nested comment has author 'eve' and likes between 5 and 15 inclusive. Which query correctly implements this?
Attempts:
2 left
💡 Hint
Use a bool must inside nested query to combine conditions on the same nested object.
✗ Incorrect
Option C correctly uses a nested query with a bool must combining match and range conditions on the same nested object. Option C is not nested, so conditions may match different nested objects. Option C uses an invalid 'filter' key inside nested query. Option C uses 'should' which means either condition can match, not both.