# Time range based on timestamp in DSL query

**URL:** <https://discuss.elastic.co/t/time-range-based-on-timestamp-in-dsl-query/350962>\
**Category:** Elasticsearch\
**Created:** [January 12, 2024, 1:41pm UTC](https://discuss.elastic.co/t/time-range-based-on-timestamp-in-dsl-query/350962 "2024-01-12T13:41:05Z")\
**Posts on this page:** 1\
**Showing post:** 4

<div class="post-metadata">

**Author:** ![stephenb](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/stephenb/32/40856_2.png) [@stephenb](https://discuss.elastic.co/u/stephenb)\
**Post date:** [January 12, 2024, 2:57pm UTC](https://discuss.elastic.co/t/time-range-based-on-timestamp-in-dsl-query/350962/4 "2024-01-12T14:57:31Z")

</div>

Hi @LeCalve Welcome to the community.

You are going to need to create a field that represents time of day and then filter on it

I just help someone with this. You can read what we did here

> [@Extracting time from @timestamp field using Runtime](https://discuss.elastic.co/t/extracting-time-from-timestamp-field-using-runtime/348468/1):
>
> I understand Scripted Fields have been deprecated since 7.13. The replacement is now Runtime. I have a @timestamp field [image] How can I extract out the time component into a new field @timeofday - such that when I filter by @timeofday, I can filter by time range. I was reading [Lucene Expressions Language | Elasticsearch Guide [5.0] | Elastic](https://www.elastic.co/guide/en/elasticsearch/reference/5.0/modules-scripting-expression.html#_date_field_api) and But still feel abit lost on how complicated an approach I need to do. Its actually a simple mod because I'm relying on data in existing colu…

This is doing it with runtime fields. In order to use this for a DSL query You will need to [add the runtime field directly to the mapping](https://www.elastic.co/guide/en/elasticsearch/reference/current/runtime-mapping-fields.html) or you may want to actually use an ingest pipeline and create a field on ingest.

Take a read and come back. Tell us what you think.

---

_[View the full topic](https://discuss.elastic.co/t/time-range-based-on-timestamp-in-dsl-query/350962)._
