# Condition doesn't trigger even if true

**URL:** <https://discuss.elastic.co/t/condition-doesnt-trigger-even-if-true/160944>\
**Category:** Elasticsearch\
**Tags:** elastic-stack-alerting\
**Created:** [December 14, 2018, 4:53pm UTC](https://discuss.elastic.co/t/condition-doesnt-trigger-even-if-true/160944 "2018-12-14T16:53:07Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![draganadz](https://avatars.discourse-cdn.com/v4/letter/d/87869e/32.png) [@draganadz](https://discuss.elastic.co/u/draganadz)\
**Post date:** [December 14, 2018, 4:53pm UTC](https://discuss.elastic.co/t/condition-doesnt-trigger-even-if-true/160944/1 "2018-12-14T16:53:07Z")

</div>

Hello,

I'm making a watcher that should alert if some value is null. So I get several hits and for each hit I check whether the result is empty. When I do a search query I can see that there are such results but my condition keeps returning false. I'm not sure if I've written the script wrong or if all of the hits have to pass in order to get a final true and trigger the condition? This is how my script looks:

"script": {  
"lang": "painless",  
"source": "for(def hit: ctx.payload.hits.hits) {  
if(hit.\_source.result.value == null) { return true; }  
} return false; "  
}

I have tried to move the "return false" to after the if-statement and tried with an else but it gives me an error..

---

<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 11, 2019, 4:53pm UTC](https://discuss.elastic.co/t/condition-doesnt-trigger-even-if-true/160944/2 "2019-01-11T16:53:08Z")

</div>

Closed on January 11, 2019, 4:53pm UTC

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