Complete the code to define a range bucket aggregation named "price_ranges".
{
"aggs": {
"price_ranges": {
"range": {
"field": "price",
"ranges": [
{ "to": 100 },
{ "from": 100, "to": 200 },
{ "from": 200 }
]
}
}
},
"size": [1]
}Setting "size" to 0 tells Elasticsearch not to return any hits, only aggregation results.
Complete the code to add a sub-aggregation "avg_price" that calculates the average price within each range bucket.
{
"aggs": {
"price_ranges": {
"range": {
"field": "price",
"ranges": [
{ "to": 100 },
{ "from": 100, "to": 200 },
{ "from": 200 }
]
},
"aggs": {
"avg_price": {
"[1]": {
"field": "price"
}
}
}
}
},
"size": 0
}The "avg" aggregation calculates the average value of a numeric field.
Fix the error in the range bucket definition by completing the missing key.
{
"aggs": {
"age_ranges": {
"range": {
"[1]": "age",
"ranges": [
{ "to": 20 },
{ "from": 20, "to": 40 },
{ "from": 40 }
]
}
}
},
"size": 0
}The key "field" specifies which field to use for the range aggregation.
Fill both blanks to create a range bucket aggregation on "weight" with two buckets: less than 50 and 50 or more.
{
"aggs": {
"weight_ranges": {
"range": {
"[1]": "weight",
"[2]": [
{ "to": 50 },
{ "from": 50 }
]
}
}
},
"size": 0
}"field" specifies the field to aggregate on, and "ranges" defines the bucket boundaries.
Fill all three blanks to create a range bucket aggregation on "temperature" with buckets for below 0, 0 to 30, and above 30, and add a sub-aggregation "max_temp" to find the maximum temperature in each bucket.
{
"aggs": {
"temp_ranges": {
"range": {
"[1]": "temperature",
"[2]": [
{ "to": 0 },
{ "from": 0, "to": 30 },
{ "from": 30 }
]
},
"aggs": {
"max_temp": {
"[3]": {
"field": "temperature"
}
}
}
}
},
"size": 0
}"field" specifies the field for the range aggregation, "ranges" defines the buckets, and "max" finds the maximum value in each bucket.