# How to set timerange query to -15min from now?

**URL:** <https://discuss.elastic.co/t/how-to-set-timerange-query-to-15min-from-now/321662>\
**Category:** Elasticsearch\
**Created:** [December 20, 2022, 2:33pm UTC](https://discuss.elastic.co/t/how-to-set-timerange-query-to-15min-from-now/321662 "2022-12-20T14:33:55Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![ElasticUser11](https://avatars.discourse-cdn.com/v4/letter/e/ee59a6/32.png) [@ElasticUser11](https://discuss.elastic.co/u/ElasticUser11)\
**Post date:** [December 20, 2022, 2:33pm UTC](https://discuss.elastic.co/t/how-to-set-timerange-query-to-15min-from-now/321662/1 "2022-12-20T14:33:55Z")

</div>

I need to check to see if two distinct logs are being generated every 15 min and every hour, so I'm trying to create two timeranges for two different indices -- one that checks for logs in the past 15 min and returns the latest log produced and the other that checks for logs in the past hour and returns the latest log produced. So far, the result is always for the past hour. For instance, if I send a call to the server at `2022-12-20T15:30:59.087Z` , the result is `2022-12-20T14:30:59.087Z` , exactly one hour before. I've tried everything but nothing worked. Below is the query I'm currently using. Any help is appreciated.

```auto
query_res = es.search(
        index="winlogbeat-dc*",
        body={
            "size": 1,
            "sort": [
                {
                    "timestamp": {
                        "order": "desc",
                        "unmapped_type": "boolean"
                    }
                }
            ],
            "_source": [
                "agent.hostname",
                "@timestamp"
            ],
            "query": {
                "bool": {
                "must": [],
                "filter": [
                    {
                    "range": {
                        "@timestamp": {
                        # "time_zone": "+01:00",
                        "format": "strict_date_optional_time||epoch_second",
                        "gte": "now-15m",
                        "lte": "now" 
                        }
                    }
                    }
                ],
                "should": [],
                "must_not": []
                }
            }
            }
        )

```

---

<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 17, 2023, 2:34pm UTC](https://discuss.elastic.co/t/how-to-set-timerange-query-to-15min-from-now/321662/2 "2023-01-17T14:34:31Z")

</div>

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