# Creating a Watcher Rule

**URL:** <https://discuss.elastic.co/t/creating-a-watcher-rule/223007>\
**Category:** Elasticsearch\
**Tags:** elastic-stack-alerting\
**Created:** [March 10, 2020, 7:39pm UTC](https://discuss.elastic.co/t/creating-a-watcher-rule/223007 "2020-03-10T19:39:13Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Elk\_huh](https://avatars.discourse-cdn.com/v4/letter/e/d26b3c/32.png) [@Elk\_huh](https://discuss.elastic.co/u/Elk_huh)\
**Post date:** [March 10, 2020, 7:39pm UTC](https://discuss.elastic.co/t/creating-a-watcher-rule/223007/1 "2020-03-10T19:39:13Z")

</div>

I am new to watcher rules and need some guidance

How do i write a watcherrule to

Look at an index at a specific field to see if a value = B

If value = B

```
{
  "trigger": {
    "schedule": {
      "interval": "1m"
    }
  },
  "input": {
    "search": {
      "request": {
        "search_type": "query_then_fetch",
        "indices": [
          "metricbeat*"
        ],
        "types": [],
        "body": {
          "size": 0,
          "query": {
            "match": {
              "beat.version": "6.2.4"
            }
          }
        }
      }
    }
  },
  "actions": {
    "send_email": {
      "email": {
        "profile": "standard",
        "to": [
          "email"
        ],
        "subject": "found beats version",
        "body": {
          "html": "found beats version"
        }
      }
    }
  }
}

```

I have this but its not working as expected

---

<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:** [March 12, 2020, 10:38am UTC](https://discuss.elastic.co/t/creating-a-watcher-rule/223007/2 "2020-03-12T10:38:31Z")

</div>

This looks good, but one step is missing. You only want to sent that email, if you really found any hits. This needs to be put into a condition, probably a script condition. See [https://www.elastic.co/guide/en/elasticsearch/reference/7.6/condition.html](https://www.elastic.co/guide/en/elasticsearch/reference/7.6/condition.html)

---

<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:** [April 9, 2020, 10:38am UTC](https://discuss.elastic.co/t/creating-a-watcher-rule/223007/3 "2020-04-09T10:38:33Z")

</div>

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