Pipo
Pipo

Reputation: 5611

elasticsearch 6: hours-range filter from @timestamp

On elasticsearch 6, I want to Make a request based on @timestamp field for requesting time slots regardless of the date the day, month or year

For example I want to request all docs added between 8am and 10am

Do you know how to do this?

Upvotes: 1

Views: 1136

Answers (1)

Pipo
Pipo

Reputation: 5611

GET /the_index/the_type/_search
{
  "query": {
    "bool": {
      "must": [
        {
          "script": {
            "script": {
               "source": "doc['@timestamp'].value.hourOfDay >= params.startHour && doc['@timestamp'].value.hourOfDay <= params.endHour",
               "params": {
                 "startHour": 10,
                 "endHour": 11
               }
            }
          }
        }
      ]
    }
  }
}

Upvotes: 1

Related Questions