Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to create a terms aggregation on the field "user.keyword".
Elasticsearch
{
"aggs": {
"users": {
"terms": {
"field": "[1]"
}
}
}
} Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using the analyzed field "user" instead of the keyword subfield.
Swapping the order of "keyword" and "user" in the field name.
✗ Incorrect
The terms aggregation requires the exact field, usually the keyword subfield like "user.keyword" for aggregations.
2fill in blank
mediumComplete the code to create a histogram aggregation on the field "price" with interval 50.
Elasticsearch
{
"aggs": {
"price_ranges": {
"histogram": {
"field": "price",
"[1]": 50
}
}
}
} Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using "range" instead of "interval" for histogram buckets.
Using "step" or "bucket_size" which are not valid parameters.
✗ Incorrect
The histogram aggregation uses the "interval" parameter to define bucket size.
3fill in blank
hardFix the error in the terms aggregation by completing the missing parameter to limit the number of buckets to 5.
Elasticsearch
{
"aggs": {
"top_users": {
"terms": {
"field": "user.keyword",
"[1]": 5
}
}
}
} Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using "limit" or "count" which are not valid parameters for terms aggregation.
Using "max_buckets" which is a cluster setting, not an aggregation parameter.
✗ Incorrect
The "size" parameter limits the number of buckets returned in a terms aggregation.
4fill in blank
hardFill both blanks to create a histogram aggregation on "age" with interval 10 and include only buckets with doc_count greater than 5.
Elasticsearch
{
"aggs": {
"age_histogram": {
"histogram": {
"field": "age",
"[1]": 10
},
"aggs": {
"filtered_buckets": {
"bucket_selector": {
"buckets_path": {
"count": "_count"
},
"script": "params.count [2] 5"
}
}
}
}
}
} Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using "range" instead of "interval" for histogram.
Using "<" or "==" in the script which would filter incorrectly.
✗ Incorrect
The histogram interval is set with "interval" and the bucket_selector script uses ">" to filter buckets with doc_count greater than 5.
5fill in blank
hardFill all three blanks to create a nested aggregation: a terms aggregation on "category.keyword", with a sub-aggregation histogram on "price" with interval 20, and limit the terms buckets to 3.
Elasticsearch
{
"aggs": {
"categories": {
"terms": {
"field": "[1]",
"[2]": 3
},
"aggs": {
"price_ranges": {
"histogram": {
"field": "price",
"[3]": 20
}
}
}
}
}
} Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using "price.keyword" for histogram field instead of "price".
Using "limit" instead of "size" to limit terms buckets.
✗ Incorrect
The terms aggregation uses "category.keyword" field with "size" 3 to limit buckets, and the histogram uses "interval" 20 on "price" field.