# Trigger condition based on iteration

**URL:** <https://forum.opensearch.org/t/trigger-condition-based-on-iteration/5273>\
**Category:** Alerting\
**Created:** [March 9, 2021, 6:54am UTC](https://forum.opensearch.org/t/trigger-condition-based-on-iteration/5273 "2021-03-09T06:54:32Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![abhilash2908](https://avatars.discourse-cdn.com/v4/letter/a/54ee81/32.png) [@abhilash2908](https://forum.opensearch.org/u/abhilash2908)\
**Post date:** [March 9, 2021, 6:54am UTC](https://forum.opensearch.org/t/trigger-condition-based-on-iteration/5273/1 "2021-03-09T06:54:32Z")

</div>

So, I understand that for a single `key-value` based condition, we can easily create trigger conditions.  
For example, in my response’s source, I have the following…

```
    {
      "difference_by_days" : 0
    }

```

In the above, I can just put a condition like…  
`ctx.results[0].hits.hits._source. difference_by_days > 0`

If the above is true then I generate an alert and if it’s false, I don’t.

But, what about the cases where I have to loop through a dynamic sized array and along with each iteration that is made, I need to return true or false and based on a certain condition and for all those iterations where the condition was true, there should be an alert sent along with some data that was present in the variables during a particular iteration.

---

<div class="post-metadata">

**Author:** ![bbKhamar](https://avatars.discourse-cdn.com/v4/letter/b/3bc359/32.png) [@bbKhamar](https://forum.opensearch.org/u/bbKhamar)\
**Post date:** [June 30, 2021, 10:29am UTC](https://forum.opensearch.org/t/trigger-condition-based-on-iteration/5273/2 "2021-06-30T10:29:01Z")

</div>

I have the similar requirement, let me know if you found any solution.  
Thanks.

---

<div class="post-metadata">

**Author:** ![dprada](https://avatars.discourse-cdn.com/v4/letter/d/3e96dc/32.png) [@dprada](https://forum.opensearch.org/u/dprada)\
**Post date:** [September 30, 2021, 12:36pm UTC](https://forum.opensearch.org/t/trigger-condition-based-on-iteration/5273/3 "2021-09-30T12:36:13Z")

</div>

Same here. If there are three hits on the same monitor schedule time, I would like to get three alarms, not one. And with some info from the Extraction query response.

Thanks.
