Hi, I am having trouble with my sum aggregation. I am using Elasticsearch [7.6.1] and I cant get the sum of each field, my data is the following:
POST test_2/_doc/1
{
"gender": [
{
"name": "other",
"value": 12
},
{
"name": "male",
"value": 20
},
{
"name": "male",
"value": 20
},
{
"name": "other",
"value": 9
},
{
"name": "female",
"value": 10
}
]
}
And I have implemented the following:
GET test_2/_search
{
"aggs": {
"gender_terms": {
"terms": {
"field": "gender.name.keyword",
"size": 10
},
"aggs": {
"gender_name_value_sums": {
"sum": {
"field": "gender.value"
}
}
}
}
}
}
The result I am expectin to recieve is the sum of each gender:
male: 40
female: 10
other: 22
But as a result I get the following:
"aggregations" : {
"gender_terms" : {
"doc_count_error_upper_bound" : 0,
"sum_other_doc_count" : 0,
"buckets" : [
{
"key" : "female",
"doc_count" : 1,
"gender_name_value_sums" : {
"value" : 71.0
}
},
{
"key" : "male",
"doc_count" : 1,
"gender_name_value_sums" : {
"value" : 71.0
}
},
{
"key" : "other",
"doc_count" : 1,
"gender_name_value_sums" : {
"value" : 71.0
}
}
]
}
}
But why? I don't know why it is not showing me the correct vaules?