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

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 !!

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

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.

Hey,

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

--Alex

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