Complete the code to create a terms aggregation on the field 'category'.
{
"aggs": {
"categories": {
"terms": { "field": "[1]" }
}
}
}The terms aggregation groups documents by the values in the 'category' field.
Complete the code to calculate the average price using an aggregation.
{
"aggs": {
"average_price": {
"[1]": { "field": "price" }
}
}
}The 'avg' aggregation calculates the average value of the specified field.
Fix the error in the aggregation that tries to get the maximum value of 'rating'.
{
"aggs": {
"max_rating": {
"max": { "field": "[1]" }
}
}
}The field name must exactly match the field in the index, which is 'rating'.
Fill both blanks to create a date histogram aggregation on the 'timestamp' field with daily intervals.
{
"aggs": {
"daily_sales": {
"date_histogram": {
"field": "[1]",
"interval": "[2]"
}
}
}
}The 'date_histogram' aggregation groups data by dates. The field is 'timestamp' and the interval is 'day' for day-by-day grouping.
Fill all three blanks to create a nested aggregation that groups by 'category', then calculates the average 'price' for each category, only including categories with at least 5 documents.
{
"aggs": {
"categories": {
"terms": {
"field": "[1]",
"min_doc_count": [2]
},
"aggs": {
"average_price": {
"[3]": { "field": "price" }
}
}
}
}
}This nested aggregation groups documents by 'category', filters out categories with fewer than 5 documents using 'min_doc_count', and calculates the average 'price' per category.