Solution: Aggregation

Review the solutions to the aggregation challenge.

Aggregation 1: Average lifetime gross by studio

To solve this challenge, we can use the terms aggregation on the studio attribute combined with the avg aggregation lifetime_gross.

To implement this aggregation, we will initiate a _search request targeting the movie index, and within the request body, we will define the aggregation structure. Initially, we will specify aggs as terms and designate the field as studio. Nested within this aggregation, we will include another aggs section labeled as avg, where we will specify the field as lifetime_gross.

Press + to interact
GET /movie/_search
{
"size": 0,
"aggs": {
"average_lifetime_gross_by_studio": {
"terms": {
"field": "studio"
},
"aggs": {
"avg_lifetime_gross": {
"avg": {
"field": "lifetime_gross"
}
}
}
}
}
}

Aggregation 2: Number of movies released each year

To solve this challenge, we can employ the terms aggregation on the Year field to count the number of movies released each year.

To implement this aggregation, we will initiate a _search request targeting the movie index. Within the request body, we will define the ...