Search all doc between 2 times each day

Hi,

I have an ES query where i want to search the doc created between 06 AM and 23 PM.
I have add this to my query:

            "range": {
            "timestamp": {
              "format": "strict_hour",
              "gte": "06",
              "lte": "23"
            }
          }

But that doesn't work. I receive no results.
Any idea what I do wrong?

thx!

Hello @Soren_vdc

What is the format of the creation date that you added to the documents?

Hi,

Format is strict_date_optional_time:
yyyy-MM-dd'T'HH:mm:ss.SSSZ

br
Sören

Try this:

{
  "query": {
    "script": {
      "script": {
        "source": "doc['date'].value.getHour() >= params.minHour && doc['date'].value.getHour() <= params.maxHour",
        "params": {
          "minHour": 6,
          "maxHour": 23
        }
      }
    }
  }
}

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.