# How to write a range query on substring of a field?

**URL:** <https://discuss.elastic.co/t/how-to-write-a-range-query-on-substring-of-a-field/154345>\
**Category:** Elasticsearch\
**Created:** [October 28, 2018, 3:06pm UTC](https://discuss.elastic.co/t/how-to-write-a-range-query-on-substring-of-a-field/154345 "2018-10-28T15:06:20Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![ali\_houshyaripour](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ali_houshyaripour/32/35931_2.png) [@ali\_houshyaripour](https://discuss.elastic.co/u/ali_houshyaripour)\
**Post date:** [October 28, 2018, 3:06pm UTC](https://discuss.elastic.co/t/how-to-write-a-range-query-on-substring-of-a-field/154345/1 "2018-10-28T15:06:21Z")

</div>

Hi, I have an index with name `user` that have two date field with names `created_at` and `expired_at` and format `yyyy-MM-dd HH:mm:ss`.  
Now I want to write a range query using them that check only time substring of them, not date and time, only `HH:mm:ss`

How should I write it ?!  
Anyone can help me ?!

---

<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 28, 2018, 4:39pm UTC](https://discuss.elastic.co/t/how-to-write-a-range-query-on-substring-of-a-field/154345/2 "2018-10-28T16:39:59Z")

</div>

You should index the second of the day in a specific field to do that.  
That'd be more efficient than anything else.

---

<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 25, 2018, 4:39pm UTC](https://discuss.elastic.co/t/how-to-write-a-range-query-on-substring-of-a-field/154345/3 "2018-11-25T16:39:59Z")

</div>

Closed on November 25, 2018, 4:39pm UTC

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