Challenge - 5 Problems
Nested Aggregations Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate2:00remaining
Output of nested terms aggregation
What is the output of the following Elasticsearch aggregation query on an index with documents containing
category and brand fields?Elasticsearch
{
"size": 0,
"aggs": {
"by_category": {
"terms": { "field": "category.keyword" },
"aggs": {
"by_brand": {
"terms": { "field": "brand.keyword" }
}
}
}
}
}Attempts:
2 left
💡 Hint
Think about how terms aggregations group documents hierarchically.
✗ Incorrect
The query groups documents first by category, then within each category by brand, producing nested buckets with counts.
❓ Predict Output
intermediate2:00remaining
Result of nested aggregation with metric
Given this aggregation query, what is the value of
max_price inside each by_category bucket?Elasticsearch
{
"size": 0,
"aggs": {
"by_category": {
"terms": { "field": "category.keyword" },
"aggs": {
"max_price": { "max": { "field": "price" } }
}
}
}
}Attempts:
2 left
💡 Hint
Max aggregation calculates the maximum value within its bucket.
✗ Incorrect
The max aggregation inside each category bucket calculates the highest price among documents in that category.
🔧 Debug
advanced2:00remaining
Identify the error in nested aggregation query
What error will this Elasticsearch query produce?
Elasticsearch
{
"size": 0,
"aggs": {
"nested_agg": {
"nested": { "path": "comments" },
"aggs": {
"by_user": {
"terms": { "field": "user.keyword" }
}
}
}
}
}Attempts:
2 left
💡 Hint
Nested aggregations require fields inside the nested path.
✗ Incorrect
The terms aggregation uses a field outside the nested path, causing a field not found error.
🧠 Conceptual
advanced1:30remaining
Purpose of nested aggregation in Elasticsearch
Why do we use nested aggregations in Elasticsearch?
Attempts:
2 left
💡 Hint
Think about how nested fields are stored and queried.
✗ Incorrect
Nested aggregations allow grouping and metrics on fields inside nested objects, which are stored separately in Elasticsearch.
❓ Predict Output
expert3:00remaining
Output of deeply nested aggregation with filters
What is the output doc count of the innermost bucket in this nested aggregation?
Elasticsearch
{
"size": 0,
"aggs": {
"nested_comments": {
"nested": { "path": "comments" },
"aggs": {
"filtered_comments": {
"filter": { "term": { "comments.approved": true } },
"aggs": {
"by_user": {
"terms": { "field": "comments.user.keyword" },
"aggs": {
"max_likes": { "max": { "field": "comments.likes" } }
}
}
}
}
}
}
}
}Attempts:
2 left
💡 Hint
Filter aggregation narrows down nested documents before terms aggregation.
✗ Incorrect
The nested aggregation accesses comments, filter selects approved ones, then groups by user with max likes metric.