Hi All,
I have array of objects in each document in index. I want to group by and retrieve stats based on fields from this array. But stats is calculated based on sum of all values in this array.
Could you please suggest, is there mistake in my query or expected behavior for now?
Example of my document:
{
"city":"London",
"arrayField":[
{
"groupByField":"value1",
"statsField":10
},
{
"groupByField":"value1",
"statsField":20
},
{
"groupByField":"value2",
"statsField":10
},
{
"groupByField":"value2",
"statsField":5
}
]
}
Example of my query:
{
"size" : 0,
"aggregations" : {
"filter" : {
"filter" : {
"bool" : {
"must" : {
"match_all" : { }
}
}
},
"aggregations" : {
"terms" : {
"terms" : {
"field" : "arrayField.groupByField",
"size" : 100000
},
"aggregations" : {
"districts.population" : {
"stats" : {
"field" : "arrayField.statsField"
}
}
}
}
}
}
}
}
I expect to get results:
for group1: sum = 30
for group2:sum = 15
I actually get:
for group1:sum = 45
for group2:sum = 45