# Creating a watcher to compare a float value

**URL:** <https://discuss.elastic.co/t/creating-a-watcher-to-compare-a-float-value/204578>\
**Category:** Elasticsearch\
**Tags:** elastic-stack-alerting\
**Created:** [October 22, 2019, 6:18am UTC](https://discuss.elastic.co/t/creating-a-watcher-to-compare-a-float-value/204578 "2019-10-22T06:18:45Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![Shan\_Chathusanda](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/shan_chathusanda/32/55382_2.png) [@Shan\_Chathusanda](https://discuss.elastic.co/u/Shan_Chathusanda)\
**Post date:** [October 22, 2019, 6:18am UTC](https://discuss.elastic.co/t/creating-a-watcher-to-compare-a-float-value/204578/1 "2019-10-22T06:18:45Z")

</div>

Hi,

Currently I am working on a watcher in Kibana 7.x. In here I need to compare a field (which is a float value) and perform an action. I am using a advanced watch for this requirement. Here I extract the field that I want and then compare it against a value. But the action is not triggered. Following is the JSON file of the watcher.

```
 {
  "trigger": {
    "schedule": {
      "interval": "1m"
    }
  },
  "input": {
    "search": {
      "request": {
            "indices": [
                "abc-*"
            ]
        },
        "extract" : ["amount"]
    }
  },
  "condition": {
    "compare": {
      "ctx.payload": {
        "gt": 10
      }
    }
  },
  
  "actions": {
    "my-logging-action": {
      "logging": {
        "text": "There are {{ctx.payload.hits.total}} documents in your index. amount is above 10."
      }
    }
  }
}

```

It is my pleasure if any one can correct my error.  
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:** [October 22, 2019, 8:10am UTC](https://discuss.elastic.co/t/creating-a-watcher-to-compare-a-float-value/204578/2 "2019-10-22T08:10:11Z")

</div>

the `extract` part needs to include an exact path and not the field name within the `_source` field.

---

<div class="post-metadata">

**Author:** ![Shan\_Chathusanda](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/shan_chathusanda/32/55382_2.png) [@Shan\_Chathusanda](https://discuss.elastic.co/u/Shan_Chathusanda)\
**Post date:** [October 22, 2019, 8:54am UTC](https://discuss.elastic.co/t/creating-a-watcher-to-compare-a-float-value/204578/3 "2019-10-22T08:54:13Z")

</div>

Hi @spinscale  
Could you please tell me how to specify that path?

---

<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:** [October 22, 2019, 10:12am UTC](https://discuss.elastic.co/t/creating-a-watcher-to-compare-a-float-value/204578/4 "2019-10-22T10:12:55Z")

</div>

It seems that extraction currently does not work with array based elements, like the `hits.hits` array. I'll take a closer look and will open an issue.

Using `hits.hits` works. For now, it might be easiest to just not use any extraction or use source filtering as part of the search request.

---

<div class="post-metadata">

**Author:** ![Shan\_Chathusanda](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/shan_chathusanda/32/55382_2.png) [@Shan\_Chathusanda](https://discuss.elastic.co/u/Shan_Chathusanda)\
**Post date:** [October 22, 2019, 10:14am UTC](https://discuss.elastic.co/t/creating-a-watcher-to-compare-a-float-value/204578/5 "2019-10-22T10:14:50Z")

</div>

Hi @spinscale,  
Thanks for the quick replies. Is it possible to iterate the `hits.hits` array from watcher?

---

<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:** [October 22, 2019, 10:17am UTC](https://discuss.elastic.co/t/creating-a-watcher-to-compare-a-float-value/204578/6 "2019-10-22T10:17:54Z")

</div>

If you want to do that in the condition, take a look at the [script condition](https://www.elastic.co/guide/en/elasticsearch/reference/7.4/condition-script.html).

Also, check out the [Alerting examples](https://github.com/elastic/examples/tree/master/Alerting/Sample%20Watches) for some inspiration.

---

<div class="post-metadata">

**Author:** ![Shan\_Chathusanda](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/shan_chathusanda/32/55382_2.png) [@Shan\_Chathusanda](https://discuss.elastic.co/u/Shan_Chathusanda)\
**Post date:** [October 22, 2019, 10:46am UTC](https://discuss.elastic.co/t/creating-a-watcher-to-compare-a-float-value/204578/7 "2019-10-22T10:46:24Z")

</div>

Hi @spinscale,

Thanks you very much.

---

<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:** [November 19, 2019, 10:46am UTC](https://discuss.elastic.co/t/creating-a-watcher-to-compare-a-float-value/204578/8 "2019-11-19T10:46:29Z")

</div>

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