Accessing single tag in watcher

Hello All!

I'm setting up a watcher that'll send an email when a query matches, and all of that is working as expected. What I'm attempting to do is access a single value from an array being returned, the first tag.

The following code:

{{ctx.payload.hits.hits.0._source.tags}}

Returns:
{ 0=Tag1, 1=Tag2 }

I've tried

{{ctx.payload.hits.hits.0._source.tags.0}} 
{{ctx.payload.hits.hits.0._source.tags.0.key}}
{{ctx.payload.hits.hits.0._source.tags.0.value}}

None of those appear to be the correct syntax.

I appreciate any assistance from anyone more experienced with the language.

Thanks!

the first variant looks good, see this example (and its output, when you run it yourself):

POST _xpack/watcher/watch/_execute
{
  "watch": {
    "trigger": {
      "schedule": {
        "interval": "10m"
      }
    },
    "input": {
      "simple": {
        "foo": [ "one", "two", "three" ]
      }
    },
    "actions": {
      "my-logging": {
        "logging": {
          "text": "{{ctx.payload.foo.0}}"
        }
      }
    }
  }
}
1 Like

This is what I get for making multiple changes to my watcher at once, something else was causing the break. Thanks for the confirmation, much appreciated.

1 Like

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