0
votes

In Elasticsearch I have an index containing documents with a timestamp and the number of observed requests to a webservice.

I would like to perform an aggregation to get, for each day, the hour where the maximum number of requests were observed (peak hour).

I succeed to get the result by performing the following request:

{
   "aggregations" : {
      "week_summary" : {
        "filter" : {"range": {"@timestamp": {"gte": "2015-01-20||-7d","lte": "2015-01-20"}}},

        "aggregations" : {
           "oneday_interval" : {
              "date_histogram" : {"field" : "@timestamp", "interval" : "1d","order" : { "_key" : "desc" }},                             
              "aggregations" : {
                 "peak_hour_histogram" : {
                    "date_histogram" : {"field" : "@timestamp", "interval" : "1h","order" : { "peak_request_count.value" : "desc" }},
                    "aggregations" : {
                       "peak_request_count" : {
                          "sum" : { "field" : "request_count"}
                        }
                    }     
                  }
              }
           }
        }
      }
   },
   size : 0
}

This is working ok in a sense: the first item in the peak_hour_histogram buckets array is indeed corresponding to the peak hour due to the ability to sort a date histogram on a sub-aggregation value.

Nevertheless, I don't need all the other buckets items (i.e. the other 23 hours of the day), and I'd like to receive only the first item. I tried to play with top_hits without any success.

Do you know a way to perform this filtering?

NB: In the real use case my aggregation is returning about 3MB of data. So filtering all those useless values becomes important.

Thanks for your answers.

1

1 Answers

0
votes