# Search all doc between 2 times each day

**URL:** <https://discuss.elastic.co/t/search-all-doc-between-2-times-each-day/318124>\
**Category:** Elasticsearch\
**Created:** [November 3, 2022, 4:31pm UTC](https://discuss.elastic.co/t/search-all-doc-between-2-times-each-day/318124 "2022-11-03T16:31:39Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Soren\_vdc](https://avatars.discourse-cdn.com/v4/letter/s/b4bc9f/32.png) [@Soren\_vdc](https://discuss.elastic.co/u/Soren_vdc)\
**Post date:** [November 3, 2022, 4:31pm UTC](https://discuss.elastic.co/t/search-all-doc-between-2-times-each-day/318124/1 "2022-11-03T16:31:40Z")

</div>

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:

```auto
            "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!

---

<div class="post-metadata">

**Author:** ![RabBit\_BR](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/rabbit_br/32/82261_2.png) [@RabBit\_BR](https://discuss.elastic.co/u/RabBit_BR)\
**Post date:** [November 4, 2022, 10:42am UTC](https://discuss.elastic.co/t/search-all-doc-between-2-times-each-day/318124/2 "2022-11-04T10:42:38Z")

</div>

Hello @Soren_vdc

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

---

<div class="post-metadata">

**Author:** ![Soren\_vdc](https://avatars.discourse-cdn.com/v4/letter/s/b4bc9f/32.png) [@Soren\_vdc](https://discuss.elastic.co/u/Soren_vdc)\
**Post date:** [November 4, 2022, 3:32pm UTC](https://discuss.elastic.co/t/search-all-doc-between-2-times-each-day/318124/3 "2022-11-04T15:32:13Z")

</div>

Hi,

Format is strict\_date\_optional\_time:  
yyyy-MM-dd'T'HH:mm:ss.SSSZ

br  
Sören

---

<div class="post-metadata">

**Author:** ![RabBit\_BR](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/rabbit_br/32/82261_2.png) [@RabBit\_BR](https://discuss.elastic.co/u/RabBit_BR)\
**Post date:** [November 4, 2022, 4:16pm UTC](https://discuss.elastic.co/t/search-all-doc-between-2-times-each-day/318124/4 "2022-11-04T16:16:24Z")

</div>

Try this:

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

```

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [December 2, 2022, 4:16pm UTC](https://discuss.elastic.co/t/search-all-doc-between-2-times-each-day/318124/5 "2022-12-02T16:16:41Z")

</div>

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