0

I need to get a count of the current hour document and also last one hour from current hour and as well fetch only records for current hour

let's consider now it is "2023-06-26 20:44:56"

I need to fetch records which have timestamp greater than "2023-06-26 20:44:56" and as well get the count of documents within last hour i.e "2023-06-26 19:44:56" to "2023-06-26 20:44:56"

"query": {
              "bool": {
                  "must": [
                      {
                          "range": {
                              "timestamp": {
                                  "gte": "2023-06-26 20:44:56"
                              }
                          }
                      }
                  ]
              }
          },
          "sort": [
              {
                  "timestamp": {
                      "order": "asc"
                  }
              }
          ],
          "aggs": {
              "last_hour_count": {
                  "range": {
                      "field": "timestamp",
                      "ranges": [
                          {
                              "from": "2023-06-26 19:44:56",
                              "to": "2023-06-26 20:44:56"
                          }
                      ]
                  }
              }
          }

I have used bool because there are other conditions as well This query is not giving the count for the last hour can someone please help

0 Answers0