I have some documents stored in Elasticsearch like the following:
{
"date" : 1,
"field1" : 0.2,
"field2" : 0.5,
"field3" : 0.3
},
{
"date" : 1,
"field1" : 0.9,
"field2" : 0.5,
"field3" : 0.1
},
{
"date" : 2,
"field1" : 0.2,
"field2" : 0.6,
"field3" : 0.7
}
and what I'd like to get is a count for how many times each of field1, field2, or field3 were the greatest for each document, grouped by date, ie. expecting result to be something like:
{
"date" : 1,
"field1-greatest" : 1,
"field2-greatest" : 1,
"field3-greatest" : 0
},
{
"date" : 2,
"field1-greatest" : 0,
"field2-greatest" : 0,
"field3-greatest" : 1
}
I'm using a terms aggregation on date, but not sure how to compare different fields to do this max and count type operation using Elasticsearch aggregations. Any suggestions?