Hi,

You want to look at nested objects: 
http://www.elastic.co/guide/en/elasticsearch/guide/master/nested-objects.html

-- 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 
> ------------------------------
> View this message in context: Inconsistent results when aggregate by 
> field from array 
> <http://elasticsearch-users.115913.n3.nabble.com/Inconsistent-results-when-aggregate-by-field-from-array-tp4072818.html>
> Sent from the ElasticSearch Users mailing list archive 
> <http://elasticsearch-users.115913.n3.nabble.com/> at Nabble.com.
>

-- 
You received this message because you are subscribed to the Google Groups 
"elasticsearch" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to elasticsearch+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/elasticsearch/de0251ab-333f-4c3d-a5ec-480106ccbb39%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to