# Can I use range query using only time not date

**URL:** <https://discuss.elastic.co/t/can-i-use-range-query-using-only-time-not-date/152611>\
**Category:** Elasticsearch\
**Created:** [October 16, 2018, 8:58am UTC](https://discuss.elastic.co/t/can-i-use-range-query-using-only-time-not-date/152611 "2018-10-16T08:58:40Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![byeong\_seok\_park](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/byeong_seok_park/32/48056_2.png) [@byeong\_seok\_park](https://discuss.elastic.co/u/byeong_seok_park)\
**Post date:** [October 16, 2018, 8:58am UTC](https://discuss.elastic.co/t/can-i-use-range-query-using-only-time-not-date/152611/1 "2018-10-16T08:58:40Z")

</div>

Hi,

I wanna make a simple query that range specific time of the day.

But It seems to be necessary to write the date in elasticsearch query.

What I want is using only time in range syntax, so that I can use that script everyday to extract the specific time range's daily logs without editing.

Below is my query:  
(it's working currently, but I want remove the date)

```
{
  "size": 10,
  "query": {
  "constant_score": {
    "filter": {
      "bool": {
        "filter": [
          {
            "terms": {
              "ID": [
                10157
              ]
            }
          },
          {
            "range": {
              "EVENT_TIME": {
                "gte": "2018-07-27 00:00:00.000",
                "lt": "2018-07-27 02:59:59.999",
                "format": "yyyy-MM-dd HH:mm:ss.SSS",
                "time_zone": "+09:00"
              }
            }
          }
        ]
      }
    }
  }
  }
}

```

Any comment would be appreciated. Thanks.

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [October 16, 2018, 9:11am UTC](https://discuss.elastic.co/t/can-i-use-range-query-using-only-time-not-date/152611/2 "2018-10-16T09:11:43Z")

</div>

The best option is to compute a minute of the day or so field (or hour of the day depending on the precision you want) at index time.

Then use a normal range query.

---

<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:** [November 13, 2018, 9:11am UTC](https://discuss.elastic.co/t/can-i-use-range-query-using-only-time-not-date/152611/3 "2018-11-13T09:11:45Z")

</div>

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