Solution: Aggregation
Review the solutions to the aggregation challenge.
We'll cover the following...
- Aggregation 1: Average lifetime gross by studio
- Aggregation 2: Number of movies released each year
- Aggregation 3: Average budget vs. average lifetime gross by year
- Aggregation 4: Runtime distribution
- Aggregation 5: Top-rated movies by rating
- Aggregation 6: Rating breakdown of movies by year
- Aggregation 7: Total budget by studio
- Kibana widget
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
.
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 ...