Cant understand watcher keywords

When I am started to study watcher , i see lots of keywords in watcher examples . Samples are showing below

1)ctx.payload.hits.total
2)ctx.payload.first.path
3)ctx.metadata.color
4)ctx.payload.aggregations.bucket_results.top_bucket_hits.hits.hits.0.fields.timestamp_iso8601.0

But these keywords are I never found in watcher documentation .

From where I can study these terms meaning and its usage ?

For example I want to know what is ctx, payload and how to make this queries combinations ?

Basic intention is i want to create custom watcher for my ML jobs

Now I am using GUI for creating watcher for my ML jobs

Hey,

the payload is what is returned from the input - this makes it dynamic. If you have a simple input like this

"input" : {
  "simple" : {
    "foo" : "bar"
  }
}

then your payload will be a map like this ctx.payload.foo, which has the value bar.

If your input was a search, then the whole JSON search response will be put into the payload, so that things like ctx.payload.hits.total are accessible or aggregations like in your last example.

Hope that explains it!

--Alex

1 Like

Hi @spinscale thanks for you reply .

From where I can study these whole terms meaning ?

Is there any documentations are available ?

Hey,

Because of the dynamic nature of this there is no reference which fields are available. The data will differ with every input. If you use an HTTP input it is super different than if you use a search input because the data returned looks completely different. That is the reason why we cannot provide and reference to this.

If you need to know, how the data looks like, execute a search without a watch and study the response, same for . the HTTP input.

Does this make sense?

--Alex

1 Like

What is the meaning of ctx ?

ctx is the so called watch execution context.

When execution starts, Watcher creates a watch execution context for the watch. The execution context provides scripts and templates with access to the watch metadata, payload, watch ID, execution time, and trigger information. For more information, see Watch Execution Context.

See How Watcher works | Elasticsearch Guide [6.3] | Elastic

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