# Can we use script with compare in the condition field of a watch?

**URL:** <https://discuss.elastic.co/t/can-we-use-script-with-compare-in-the-condition-field-of-a-watch/65240>\
**Category:** Elasticsearch\
**Tags:** elastic-stack-alerting\
**Created:** [November 7, 2016, 3:30pm UTC](https://discuss.elastic.co/t/can-we-use-script-with-compare-in-the-condition-field-of-a-watch/65240 "2016-11-07T15:30:42Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![glennon](https://avatars.discourse-cdn.com/v4/letter/g/ea666f/32.png) [@glennon](https://discuss.elastic.co/u/glennon)\
**Post date:** [November 7, 2016, 3:30pm UTC](https://discuss.elastic.co/t/can-we-use-script-with-compare-in-the-condition-field-of-a-watch/65240/1 "2016-11-07T15:30:42Z")

</div>

Hi Is it possible to use an indexed script in the condition field of a watch with the "compare" condition type?  
My indexed script does not return a boolean (true/false) but a value which I want to compare to another value in the watch condition.  
I know I could do this within the script, but I want to use this script for several watches and would rather not have individual scripts per watch. Please note I do not have inline scripting enabled and this is not an option for security purposes.

Thanks

---

<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:** [November 8, 2016, 12:51pm UTC](https://discuss.elastic.co/t/can-we-use-script-with-compare-in-the-condition-field-of-a-watch/65240/2 "2016-11-08T12:51:49Z")

</div>

Hey,

the compare condition has nothing to do with scripting - it was created to not have scripting enabled.

The script condition supports indexed scripts. If the value changes, you could access the `metadata` field in your script, which is configured when [creating a watch](https://www.elastic.co/guide/en/watcher/2.4/watch-definition.html).

--Alex

---

<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:** [December 6, 2016, 12:51pm UTC](https://discuss.elastic.co/t/can-we-use-script-with-compare-in-the-condition-field-of-a-watch/65240/3 "2016-12-06T12:51:59Z")

</div>

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