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
}
]
}
-- Nils
Tip: try formatting your post, it was hard to read.
On Tuesday, March 31, 2015 at 4:37:40 AM UTC+2, Iana Bondarskaia wrote:
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
Apache, Apache Lucene, Apache Hadoop, Hadoop, HDFS and the yellow elephant
logo are trademarks of the
Apache Software Foundation
in the United States and/or other countries.