Elastic search query max value aggs

Viewed 139

I have data like this:

Name     Fees Collected     Date
Name1     100              2017-05-01T12:00:00
Name1     200              2017-05-02T12:00:00
Name2     500              2017-05-05T12:00:00
Name2     600              2017-05-06T12:00:00
Name3     1000             2017-05-010T12:00:00
Name3     1100             2017-05-011T12:00:00
Name4     1500             2017-05-011T12:00:00

How can i write a query to return the aggregation of filtered/grouped to the max Date with min doc count of 2 for each group?

I expect the following output:

Name     Fees Collected   Date  
Name1     200             2017-05-02T12:00:00
Name2     600             2017-05-06T12:00:00
Name3     1100            2017-05-011T12:00:00

Finally, I would get the aggregation as following

"aggregations" {
    "Fees Collected " : "1900" //(200+600+1100)
    }

Is there anyway to achieve this in elastic search? Thank you..

1 Answers
Related