Complete the code to define a nested aggregation named "genres".
{
"aggs": {
"genres": {
"[1]": {
"path": "genres"
}
}
}
}The nested aggregation is used to aggregate on nested fields in Elasticsearch.
Complete the code to add a sub-aggregation that counts documents by "genres.name".
{
"aggs": {
"genres": {
"nested": {
"path": "genres"
},
"aggs": {
"genre_names": {
"[1]": {
"field": "genres.name.keyword"
}
}
}
}
}
}The terms aggregation groups documents by unique values, here by genre names.
Fix the error in the aggregation by completing the missing key to calculate the average rating inside the nested aggregation.
{
"aggs": {
"genres": {
"nested": {
"path": "genres"
},
"aggs": {
"avg_rating": {
"[1]": {
"field": "genres.rating"
}
}
}
}
}
}The avg aggregation calculates the average value of a numeric field.
Fill both blanks to filter nested genres with rating greater than 4 and then get the average rating.
{
"aggs": {
"genres": {
"nested": {
"path": "genres"
},
"aggs": {
"filtered_genres": {
"[1]": {
"range": {
"genres.rating": {
"gt": 4
}
}
},
"aggs": {
"avg_rating": {
"[2]": {
"field": "genres.rating"
}
}
}
}
}
}
}
}The filter aggregation filters documents by a condition, and avg calculates the average rating.
Fill all three blanks to create a nested aggregation on "comments", filter comments with "likes" greater than 10, and get the max likes.
{
"aggs": {
"comments": {
"[1]": {
"path": "comments"
},
"aggs": {
"popular_comments": {
"[2]": {
"range": {
"comments.likes": {
"gt": 10
}
}
},
"aggs": {
"max_likes": {
"[3]": {
"field": "comments.likes"
}
}
}
}
}
}
}
}Use nested to access nested comments, filter to select comments with likes > 10, and max to find the highest likes.