# ESQL Specifiy time filter

**URL:** https://discuss.elastic.co/t/esql-specifiy-time-filter/371961
**Category:** Elastic Search
**Tags:** esql
**Created:** [December 13, 2024, 2:27pm UTC](https://discuss.elastic.co/t/esql-specifiy-time-filter/371961 "2024-12-13T14:27:24Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![etp](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/etp/32/117415_2.png) [@etp](https://discuss.elastic.co/u/etp)
#### Post date: [December 13, 2024, 2:27pm UTC](https://discuss.elastic.co/t/esql-specifiy-time-filter/371961/1 "2024-12-13T14:27:24Z")

</div>

I'm trying to use the python elasticsearch library to pull data using the query function. I wanted to specify the timerange for the query to run on. How can this be done? Is there a way to specifiy the timerange in esql or should this be defined with the filter parameter? If so, how?

---

<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: [December 13, 2024, 2:32pm UTC](https://discuss.elastic.co/t/esql-specifiy-time-filter/371961/2 "2024-12-13T14:32:29Z")

</div>

Use the `WHERE` command

There is even an example in the docs

> **[ES|QL commands | Elasticsearch Guide \[8.17\] | Elastic](https://www.elastic.co/guide/en/elasticsearch/reference/current/esql-commands.html#esql-where)**

You can use relative or absolute times

---

<div class="post-metadata">

### Author: ![etp](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/etp/32/117415_2.png) [@etp](https://discuss.elastic.co/u/etp)
#### Post date: [December 13, 2024, 3:52pm UTC](https://discuss.elastic.co/t/esql-specifiy-time-filter/371961/3 "2024-12-13T15:52:32Z")

</div>

Thanks I used a query like below,  
FROM my-test-index | WHERE @timestamp \> NOW() - 1 hour | limit 5  
But I get the error,  
"Invoking Elasticsearch client. Caught exception \<class 'elasticsearch.BadRequestError'\>."

---

<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: [December 13, 2024, 3:56pm UTC](https://discuss.elastic.co/t/esql-specifiy-time-filter/371961/4 "2024-12-13T15:56:33Z")

</div>

> [@etp](#):
>
> FROM my-test-index | WHERE @timestamp \> NOW() - 1 hour | limit 5

What version... older version you had to backquote fields with special characters

```auto
FROM logs-* | WHERE `@timestamp` > NOW() - 1 hour | limit 5

```

---

<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: [January 10, 2025, 3:56pm UTC](https://discuss.elastic.co/t/esql-specifiy-time-filter/371961/5 "2025-01-10T15:56:42Z")

</div>

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