# Watcher - Use field data from input to condition script calc

**URL:** <https://discuss.elastic.co/t/watcher-use-field-data-from-input-to-condition-script-calc/295427>\
**Category:** Elasticsearch\
**Tags:** elastic-stack-alerting\
**Created:** [January 26, 2022, 7:44am UTC](https://discuss.elastic.co/t/watcher-use-field-data-from-input-to-condition-script-calc/295427 "2022-01-26T07:44:42Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![gerardgorrion](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/gerardgorrion/32/85495_2.png) [@gerardgorrion](https://discuss.elastic.co/u/gerardgorrion)\
**Post date:** [January 26, 2022, 7:44am UTC](https://discuss.elastic.co/t/watcher-use-field-data-from-input-to-condition-script-calc/295427/1 "2022-01-26T07:44:42Z")

</div>

We are triying to deploy a watcher alert to compare values into a field of some logs

The problem is:

we need to compare 2 fields loaded in input:

1- metricbeat logs with some specific field  
2- metricbeat logs with some specific field

But we are not able to extract the value of each log in that input to do:  
data\_field 1 - data\_field 2

how can I get these fields values individually to calculate condition?

Thanks!

---

<div class="post-metadata">

**Author:** ![jakelandis](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jakelandis/32/36163_2.png) [@jakelandis](https://discuss.elastic.co/u/jakelandis)\
**Post date:** [January 26, 2022, 2:49pm UTC](https://discuss.elastic.co/t/watcher-use-field-data-from-input-to-condition-script-calc/295427/2 "2022-01-26T14:49:55Z")

</div>

You probably want a [script condition](https://www.elastic.co/guide/en/elasticsearch/reference/7.16/condition-script.html#accessing-watch-payload) from which you could reference the value from `ctx.payload.*` . Alternatively, if you want use a specific condition you could use a [compare condition](https://www.elastic.co/guide/en/elasticsearch/reference/7.16/condition-compare.html) and reference with the mustache syntax `{{ctx.payload.*}}`.

When building out a Watch it is often useful for debugging to add an action like the following to see what is available via ctx.payload.

```json
"actions": {
        "my_logger": {
            "logging": {
                "text": "Watch payload = {{ctx.payload}}",
                "level": "debug"
            }
        }
    }

```

---

<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:** [February 23, 2022, 2:50pm UTC](https://discuss.elastic.co/t/watcher-use-field-data-from-input-to-condition-script-calc/295427/3 "2022-02-23T14:50:21Z")

</div>

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