I am trying to do aggregation on documents which contains datetime and CPU time and server name. I want to find the avg CPU time on latest date. I have the following query which partially works it gives me the avg CPU time but not on latest date it just randomly chooses date.
client.prepareSearch("myindex").
setTypes("mytype").
setQuery(
QueryBuilders.filteredQuery(QueryBuilders.matchAllQuery(),
FilterBuilders.andFilter(FilterBuilders.termFilter("server","x")))).
addAggregation(AggregationBuilders.avg("cpu_agg")
.field("dt_time").field("cpu_time"))
.get()
Please guide. I want avg cpu time on latest date say today's date. I am new to ElasticSearch. Thanks in advance.