# Elasticsearch Query setting date conditions

**URL:** <https://discuss.elastic.co/t/elasticsearch-query-setting-date-conditions/335554>\
**Category:** Kibana\
**Tags:** elastic-stack-alerting\
**Created:** [June 8, 2023, 3:36pm UTC](https://discuss.elastic.co/t/elasticsearch-query-setting-date-conditions/335554 "2023-06-08T15:36:50Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![DavidGreensfelder](https://avatars.discourse-cdn.com/v4/letter/d/ec9cab/32.png) [@DavidGreensfelder](https://discuss.elastic.co/u/DavidGreensfelder)\
**Post date:** [June 8, 2023, 3:36pm UTC](https://discuss.elastic.co/t/elasticsearch-query-setting-date-conditions/335554/1 "2023-06-08T15:36:50Z")

</div>

I am setting up Alerting Rules under Rules and Connections.

My query works great, but I need to not see the alerts during the maintenance window from 9 pm to 5 am.

Here is my query:

```auto
{
  "query" : {
    "bool" : {
      "must" : [
        {"match" : {"log.level" : "Error"}}
        ],
      "filter": [
        {"terms": {
          "agent.hostname": [
            "Server1p",
            "Server2p",
            "Server3p"
          ]
        }}
      ]        
    }
  }
}

```

How can I add a condition to only have the query work from 5 am to 9 pm?

---

<div class="post-metadata">

**Author:** ![Priscilla\_Parodi](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/priscilla_parodi/32/43047_2.png) [@Priscilla\_Parodi](https://discuss.elastic.co/u/Priscilla_Parodi)\
**Post date:** [June 28, 2023, 8:13pm UTC](https://discuss.elastic.co/t/elasticsearch-query-setting-date-conditions/335554/2 "2023-06-28T20:13:57Z")

</div>

Hello @DavidGreensfelder,

You can use a `range` [query](https://www.elastic.co/guide/en/elasticsearch/reference/8.8/query-dsl-range-query.html#ranges-on-dates) with the date field.

```
  "range": {
        "timestamp": {
          "time_zone": "+01:00", 
          "gte": "2023-06-28T05:00:00",
          "lte": "2023-06-28T21:00:00"
        }
      }

```

Make sure you are checking the [time zone](https://en.wikipedia.org/wiki/List_of_tz_database_time_zones).

---

<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:** [July 26, 2023, 8:14pm UTC](https://discuss.elastic.co/t/elasticsearch-query-setting-date-conditions/335554/3 "2023-07-26T20:14:13Z")

</div>

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