# Unable to parse {{ctx.payload}} mustache script from email action

**URL:** <https://discuss.elastic.co/t/unable-to-parse-ctx-payload-mustache-script-from-email-action/89443>\
**Category:** Elasticsearch\
**Tags:** elastic-stack-alerting\
**Created:** [June 14, 2017, 6:58pm UTC](https://discuss.elastic.co/t/unable-to-parse-ctx-payload-mustache-script-from-email-action/89443 "2017-06-14T18:58:47Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![krishna\_chaitanya](https://avatars.discourse-cdn.com/v4/letter/k/b5a626/32.png) [@krishna\_chaitanya](https://discuss.elastic.co/u/krishna_chaitanya)\
**Post date:** [June 14, 2017, 6:58pm UTC](https://discuss.elastic.co/t/unable-to-parse-ctx-payload-mustache-script-from-email-action/89443/1 "2017-06-14T18:58:47Z")

</div>

Below email action:

```
"email_admin": {
        "email" : { 
          "to" : "abc@example.com", 
          "subject" : "{{ctx.payload.hits.total}} alert", 
          "body" : "Cannot access {{ctx.payload.hits.total}} value"
        }
      }

```

Returns:

```
Subject: alert
Body: Cannot access value

```

Couldn't find any error in the elasticsearch logs as well.

I have another action(index) along with this email action, and I could see that index correctly being populated with the values from `ctx.payload`

Any help appreciated !!

---

<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:** [June 15, 2017, 3:30pm UTC](https://discuss.elastic.co/t/unable-to-parse-ctx-payload-mustache-script-from-email-action/89443/2 "2017-06-15T15:30:06Z")

</div>

Hey,

can you please paste the output (or put it in a gist) from the Execute Watch API or alternatively the last entry from the watch history regarding that watch?

--Alex

---

<div class="post-metadata">

**Author:** ![krishna\_chaitanya](https://avatars.discourse-cdn.com/v4/letter/k/b5a626/32.png) [@krishna\_chaitanya](https://discuss.elastic.co/u/krishna_chaitanya)\
**Post date:** [June 15, 2017, 9:27pm UTC](https://discuss.elastic.co/t/unable-to-parse-ctx-payload-mustache-script-from-email-action/89443/3 "2017-06-15T21:27:45Z")

</div>

Hi spinscale, Thanks for the reply.

The way I found a solution for this is:

When I tried to print the `{{ctx.payload}}` content inside the email body, I saw only `{_doc=...}`. So, `ctx.payload` was only having `_doc` field. This was probably because, I had multiple actions, first index action and then email action. In index action, I was returning output this way:

```
_docs.add(.....);
return ['_doc' : _docs]

```

So, when I get to email action, for some reason, I only had this `_doc` field in `ctx.payload`. All other fields from the payload are gone. But, I only needed this field in my email. So, I was fine with that.

If I could get explanation to why there's only `_doc` field in `ctx.payload`, right after index action, it would be helpful for me.

---

<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:** [June 16, 2017, 6:24am UTC](https://discuss.elastic.co/t/unable-to-parse-ctx-payload-mustache-script-from-email-action/89443/4 "2017-06-16T06:24:57Z")

</div>

Hey,

again, please provide the full watch and the output of the execute watch API, otherwise debugging is impossible.

--Alex

---

<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:** [July 14, 2017, 6:24am UTC](https://discuss.elastic.co/t/unable-to-parse-ctx-payload-mustache-script-from-email-action/89443/5 "2017-07-14T06:24:58Z")

</div>

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