# Can set the Watcher with Time period in 2 Codition

**URL:** https://discuss.elastic.co/t/can-set-the-watcher-with-time-period-in-2-codition/212825
**Category:** Elasticsearch
**Tags:** elastic-stack-alerting
**Created:** [December 23, 2019, 9:09am UTC](https://discuss.elastic.co/t/can-set-the-watcher-with-time-period-in-2-codition/212825 "2019-12-23T09:09:23Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![maddog](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/maddog/32/53018_2.png) [@maddog](https://discuss.elastic.co/u/maddog)
#### Post date: [December 23, 2019, 9:09am UTC](https://discuss.elastic.co/t/can-set-the-watcher-with-time-period-in-2-codition/212825/1 "2019-12-23T09:09:23Z")

</div>

Topic : How to set Watcher to support 2 condition on 1 day??

Time 00.00 - 06.00 check-in Condition 1

```
"condition": {
"compare": {
  "ctx.payload.hits.total": {
    "gte": 10
  }
}

```

Time 06.01-23.59 Check-in Condition 2

```
"condition": {
"compare": {
  "ctx.payload.hits.total": {
    "gte": 50
  }
}

```

Watcher can be support in case or not ?  
or anyone can share the knowledge of how to set in this case.

---

<div class="post-metadata">

### Author: ![andres-perez](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/andres-perez/32/136461_2.png) [@andres-perez](https://discuss.elastic.co/u/andres-perez)
#### Post date: [January 7, 2020, 4:47pm UTC](https://discuss.elastic.co/t/can-set-the-watcher-with-time-period-in-2-codition/212825/2 "2020-01-07T16:47:36Z")

</div>

Hi, two solutions come to my mind:

- Create 2 independent watcher alerts with the desired scheduling and condition for each one. More verbose but simpler to maintain.

- Use only one alert with a [script condition](https://www.elastic.co/guide/en/elasticsearch/reference/current/condition-script.html) instead of a simple compare. That enables you to:

As you imagine, the latest one won't be beautiful at all...

---

<div class="post-metadata">

### Author: ![spinscale](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/spinscale/32/25011_2.png) [@spinscale](https://discuss.elastic.co/u/spinscale)
#### Post date: [January 8, 2020, 10:15am UTC](https://discuss.elastic.co/t/can-set-the-watcher-with-time-period-in-2-codition/212825/3 "2020-01-08T10:15:18Z")

</div>

Hey,

in addition you can have conditions on a per action base. So you could trigger action1 (i.e. send a slack message) for your first condition and action2 (i.e. send an email) with the second condition.

Would that help your use-case?

--Alex

---

<div class="post-metadata">

### Author: ![maddog](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/maddog/32/53018_2.png) [@maddog](https://discuss.elastic.co/u/maddog)
#### Post date: [January 15, 2020, 7:26am UTC](https://discuss.elastic.co/t/can-set-the-watcher-with-time-period-in-2-codition/212825/4 "2020-01-15T07:26:41Z")

</div>

Hi Sinscale  
thank you for update  
I mean check up same error code.  
when payload.hits.total greater than 10 @time 00.00 - 06.00 and payload.hits.total greater than 50 @time 06.01 - 23.59

same error code check but different time of the day

---

<div class="post-metadata">

### Author: ![spinscale](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/spinscale/32/25011_2.png) [@spinscale](https://discuss.elastic.co/u/spinscale)
#### Post date: [January 15, 2020, 8:27am UTC](https://discuss.elastic.co/t/can-set-the-watcher-with-time-period-in-2-codition/212825/5 "2020-01-15T08:27:20Z")

</div>

using a script based condition you can execute all the logic you want within a condition and also take the current time into account by utilizing `ctx.trigger.triggered_time`

---

<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: [February 12, 2020, 8:27am UTC](https://discuss.elastic.co/t/can-set-the-watcher-with-time-period-in-2-codition/212825/6 "2020-02-12T08:27:20Z")

</div>

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