Hello Everyone,
I'm building an accommodation rating system where one rating input contain 5 categories with the example structure collected in an array:
"submitted_rating" : [
{
"rating": 4,
"title": "Travel"
},
{
"rating": 3,
"title": "Restaurants"
},
{
"rating": 1.5,
"title": "Facility"
},
{
"rating": 3.5,
"title": "Quality"
},
{
"rating": 5,
"title": "price"
}
]
Then I tried to use aggregation to calculate the "average rating in each category" based on the follow example data:
I would expecting following results:
I was using below aggregation, but the average results I got was not the results I'm looking for.
"aggs": {
"submitted_rating": {
"terms": {
"field": "submitted_rating.title.keyword"
},
"aggs": {
"rating": {
"avg": {
"field": "submitted_rating.rating"
}
}
}
}
It seems like the returned avg value is the average of all "rating" across different "title" as well.
What did I do wrong?
Thanks!