Hi I have the document for cpu usage with date_time field inside it. Now I would like to find avg cpu usage for the date range. I have come up with the following solution. Please let me know if there are any advance or better approach as I am new to Elastic Search.
client.prepareSearch("myindex").
setTypes("mytype").
setQuery(
QueryBuilders.filteredQuery(QueryBuilders.matchAllQuery(),
FilterBuilders.andFilter(FilterBuilders.termFilter("server","x"),
FilterBuilders.rangeFilter(date_time).from(fdate).to(tdate)))).get()
Now above query returns me as expected documents which falls within from/to date range. Now what I try to do is I find all unique dates from these documents using SearchHitsand I store this unique combinations of dates in a HashSet and now for all items inside this HashSet I execute the following query
client.prepareSearch("myindex").
setTypes("mytype").
setQuery(
QueryBuilders.filteredQuery(QueryBuilders.matchAllQuery(),
FilterBuilders.andFilter(FilterBuilders.termFilter("server","x"),
FilterBuilders.termFilter(date_time),"dateinputfromloop"))).
addAggregation(AggregationBuilders.avg("cpu_agg").field("cpu_time"))
.get()
Now above query works fine and gives output I get avg CPU for each date time combination. I was wondering if these is any better approach as I execute above query in a loop for all date combinations. Please guide thanks in advance.