# Watcher Compare 2 fields from the same index

**URL:** <https://discuss.elastic.co/t/watcher-compare-2-fields-from-the-same-index/179797>\
**Category:** Elasticsearch\
**Tags:** elastic-stack-alerting\
**Created:** [May 6, 2019, 3:21pm UTC](https://discuss.elastic.co/t/watcher-compare-2-fields-from-the-same-index/179797 "2019-05-06T15:21:48Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![gurpal](https://avatars.discourse-cdn.com/v4/letter/g/d26b3c/32.png) [@gurpal](https://discuss.elastic.co/u/gurpal)\
**Post date:** [May 6, 2019, 3:21pm UTC](https://discuss.elastic.co/t/watcher-compare-2-fields-from-the-same-index/179797/1 "2019-05-06T15:21:48Z")

</div>

Hello,

I am trying to create a simple watcher that compares 2 fields in the same index every 5 minutes. My index contains the following fields

```
 "Temperature" : "22.6",
  "Temp Hi" : "30.1",
  "Temp Lo" : "25.5",
 "@timestamp" : "2019-04-30T00:00:00.000Z",

```

Essentially I want to compare if Temperature is between Temp Hi & Temp Lo and send an email alert if out of bounds.

Any assistance with this will be highly appreciated.

Also, can watchers be restricted to specific spaces?

Thank you,

😃

---

<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:** [May 8, 2019, 8:20am UTC](https://discuss.elastic.co/t/watcher-compare-2-fields-from-the-same-index/179797/2 "2019-05-08T08:20:11Z")

</div>

Please correct me if I am wrong, but this is not about comparing two fields within the same index, but two fields within the same document?

If so, you could use a [script query](https://www.elastic.co/guide/en/elasticsearch/reference/7.0/query-dsl-script-query.html) in the search input that subtracts high from lo and checks if the value is above a threshold. However this is not a scalable solution as this calculation needs to be done for every hit.

You could use the [ingest script](https://www.elastic.co/guide/en/elasticsearch/reference/7.0/script-processor.html) processor to create the difference of those two values at index time and then run a much faster query, that is doing a range query for all documents whose treshold is above X.

Hope that makes sense.

Regarding the spaces questions. Right now this is not possible.

---

<div class="post-metadata">

**Author:** ![gurpal](https://avatars.discourse-cdn.com/v4/letter/g/d26b3c/32.png) [@gurpal](https://discuss.elastic.co/u/gurpal)\
**Post date:** [May 20, 2019, 12:55pm UTC](https://discuss.elastic.co/t/watcher-compare-2-fields-from-the-same-index/179797/3 "2019-05-20T12:55:09Z")

</div>

Yes - you are right - this is comparing 2 fields in the same document.

Thank you for the options - I'll be in touch if I need any further assistance.

---

<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:** [June 17, 2019, 12:55pm UTC](https://discuss.elastic.co/t/watcher-compare-2-fields-from-the-same-index/179797/4 "2019-06-17T12:55:12Z")

</div>

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