# Not able to execute actions on aggregation results

**URL:** <https://discuss.elastic.co/t/not-able-to-execute-actions-on-aggregation-results/138890>\
**Category:** Elasticsearch\
**Tags:** elastic-stack-alerting\
**Created:** [July 6, 2018, 10:36am UTC](https://discuss.elastic.co/t/not-able-to-execute-actions-on-aggregation-results/138890 "2018-07-06T10:36:45Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![SanyamJ-info](https://avatars.discourse-cdn.com/v4/letter/s/df705f/32.png) [@SanyamJ-info](https://discuss.elastic.co/u/SanyamJ-info)\
**Post date:** [July 6, 2018, 10:36am UTC](https://discuss.elastic.co/t/not-able-to-execute-actions-on-aggregation-results/138890/1 "2018-07-06T10:36:45Z")

</div>

Hi elastic community,

I've been trying to implement a watcher over http requests and then subsequently triggering an action(mailing here) to send me the reports.

the code i'm trying to execute is :

```
curl -X PUT 'http://localhost:9200/_watcher/watch/watch_1' -H 'Content-Type: application/json' -d
    {
      "trigger": {
        "schedule": {
          "interval": "5s"
        }
      },
      "input": {
        "search": {
          "request": {
            "indices": [
              "s3"
            ],
            "body": {
              "query": {
                "match": {
                  "type": "GET"
                }
              },
              "size": 0,
              "aggs": {
                "distinct_id": {
                  "terms": {
                    "field": "type.keyword"
                  }
                }
              }
            }
          }
        }
      },
      "condition": {
        "compare": {
          "ctx.payload.aggregations.distinct_id.buckets.0.doc_count": {
            "gt": 4
          }
        }
      },
      "actions": {
        "send_email": {
          "email": {
            "to": "xyz@abc.com",
            "subject": "Watcher Notification",
            "body": " {{ctx.payload.aggregations.distinct_id.buckets.0.doc_count}} requests found"
          }
        }
      }
    }

```

But i'm not getting any mails moreover even logging action isn't getting executed ...and state of watcher is always "awaits\_successful\_execution". Maybe there's and issue with the condition part 😕  
Watcher details(from browser) are as follows:

```
{
  "found" : true,
  "_id" : "watch_1",
  "status" : {
    "state" : {
      "active" : true,
      "timestamp" : "2018-07-06T10:17:38.585Z"
    },
    "last_checked" : "2018-07-06T10:33:08.166Z",
    "actions" : {
      "send_email" : {
        "ack" : {
          "timestamp" : "2018-07-06T10:17:38.585Z",
          "state" : "awaits_successful_execution"
        }
      }
    },
    "execution_state" : "execution_not_needed",
    "version" : 239
  },
  "watch" : {
    "trigger" : {
      "schedule" : {
        "interval" : "5s"
      }
    },
    "input" : {
      "search" : {
        "request" : {
          "search_type" : "query_then_fetch",
          "indices" : [
            "s3"
          ],
          "types" : [],
          "body" : {
            "query" : {
              "match" : {
                "type" : "GET"
              }
            },
            "size" : 0,
            "aggs" : {
              "distinct_id" : {
                "terms" : {
                  "field" : "type.keyword"
                }
              }
            }
          }
        }
      }
    },
    "condition" : {
      "compare" : {
        "ctx.payload.aggregations.distinct_id.buckets.0.doc_count" : {
          "gt" : 4
        }
      }
    },
    "actions" : {
      "send_email" : {
        "email" : {
          "profile" : "standard",
          "to" : [
            "abc@xyz.com"
          ],
          "subject" : "Watcher Notification",
          "body" : {
            "text" : "{{ctx.payload.aggregations.distinct_id.buckets.0.doc_count}} requests found"
          }
        }
      }
    }
  }
}
```

---

<div class="post-metadata">

**Author:** ![SanyamJ-info](https://avatars.discourse-cdn.com/v4/letter/s/df705f/32.png) [@SanyamJ-info](https://discuss.elastic.co/u/SanyamJ-info)\
**Post date:** [July 9, 2018, 6:58am UTC](https://discuss.elastic.co/t/not-able-to-execute-actions-on-aggregation-results/138890/2 "2018-07-09T06:58:14Z")

</div>

The above issue is sorted out, there was a minor error from my side due to which watcher was not getting executed 🙂 .  
Thank you!

---

<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:** [August 6, 2018, 6:58am UTC](https://discuss.elastic.co/t/not-able-to-execute-actions-on-aggregation-results/138890/3 "2018-08-06T06:58:23Z")

</div>

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