[DOCS] Change `ctx.payload.hits.total.value` to `ctx.payload.hits.total` (#65874)

Co-authored-by: James Rodewig <40268737+jrodewig@users.noreply.github.com>
Co-authored-by: Elastic Machine <elasticmachine@users.noreply.github.com>
This commit is contained in:
Ernesto Reig 2020-12-08 15:22:22 +01:00 committed by GitHub
parent 691f85e5a3
commit 43fa468076
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
10 changed files with 23 additions and 23 deletions

View File

@ -28,8 +28,8 @@ The following snippet shows a simple jira action definition:
"issuetype" : { "issuetype" : {
"name": "Bug" <3> "name": "Bug" <3>
}, },
"summary" : "Encountered {{ctx.payload.hits.total.value}} errors in the last 5 minutes", <4> "summary" : "Encountered {{ctx.payload.hits.total}} errors in the last 5 minutes", <4>
"description" : "Encountered {{ctx.payload.hits.total.value}} errors in the last 5 minutes (facepalm)", <5> "description" : "Encountered {{ctx.payload.hits.total}} errors in the last 5 minutes (facepalm)", <5>
"labels" : ["auto"], <6> "labels" : ["auto"], <6>
"priority" : { "priority" : {
"name" : "High" <7> "name" : "High" <7>

View File

@ -24,7 +24,7 @@ The following snippet shows a simple slack action definition:
"slack" : { "slack" : {
"message" : { "message" : {
"to" : [ "#admins", "@chief-admin" ], <1> "to" : [ "#admins", "@chief-admin" ], <1>
"text" : "Encountered {{ctx.payload.hits.total.value}} errors in the last 5 minutes (facepalm)" <2> "text" : "Encountered {{ctx.payload.hits.total}} errors in the last 5 minutes (facepalm)" <2>
} }
} }
} }
@ -59,7 +59,7 @@ The following snippet shows a standard message attachment:
"attachments" : [ "attachments" : [
{ {
"title" : "Errors Found", "title" : "Errors Found",
"text" : "Encountered {{ctx.payload.hits.total.value}} errors in the last 5 minutes (facepalm)", "text" : "Encountered {{ctx.payload.hits.total}} errors in the last 5 minutes (facepalm)",
"color" : "danger" "color" : "danger"
} }
] ]

View File

@ -25,7 +25,7 @@ The following snippet shows a simple webhook action definition:
"host" : "mylisteningserver", <5> "host" : "mylisteningserver", <5>
"port" : 9200, <6> "port" : 9200, <6>
"path": ":/{{ctx.watch_id}}", <7> "path": ":/{{ctx.watch_id}}", <7>
"body" : "{{ctx.watch_id}}:{{ctx.payload.hits.total.value}}" <8> "body" : "{{ctx.watch_id}}:{{ctx.payload.hits.total}}" <8>
} }
} }
} }
@ -50,7 +50,7 @@ For example, the following `webhook` action creates a new issue in GitHub:
"actions" : { "actions" : {
"create_github_issue" : { "create_github_issue" : {
"transform": { "transform": {
"script": "return ['title':'Found errors in \\'contact.html\\'', 'body' : 'Found ' + ctx.payload.hits.total.value + ' errors in the last 5 minutes', 'assignee' : 'web-admin', 'labels' : ['bug','sev2']]" "script": "return ['title':'Found errors in \\'contact.html\\'', 'body' : 'Found ' + ctx.payload.hits.total + ' errors in the last 5 minutes', 'assignee' : 'web-admin', 'labels' : ['bug','sev2']]"
}, },
"webhook" : { "webhook" : {
"method" : "POST", "method" : "POST",
@ -127,7 +127,7 @@ the values serve as the header values:
"headers" : { "headers" : {
"Content-Type" : "application/yaml" <1> "Content-Type" : "application/yaml" <1>
}, },
"body" : "count: {{ctx.payload.hits.total.value}}" "body" : "count: {{ctx.payload.hits.total}}"
} }
} }
} }

View File

@ -147,7 +147,7 @@ returned any hits:
[source,js] [source,js]
-------------------------------------------------- --------------------------------------------------
"condition" : { "condition" : {
"compare" : { "ctx.payload.hits.total.value" : { "gt" : 0 }} "compare" : { "ctx.payload.hits.total" : { "gt" : 0 }}
}, },
-------------------------------------------------- --------------------------------------------------
// NOTCONSOLE // NOTCONSOLE
@ -223,7 +223,7 @@ attaches the payload data to the message:
"email" : { <2> "email" : { <2>
"to" : "email@example.org", "to" : "email@example.org",
"subject" : "Watcher Notification", "subject" : "Watcher Notification",
"body" : "{{ctx.payload.hits.total.value}} error logs found", "body" : "{{ctx.payload.hits.total}} error logs found",
"attachments" : { "attachments" : {
"data_attachment" : { "data_attachment" : {
"data" : { "data" : {
@ -252,7 +252,7 @@ creates a new issue in GitHub
"url" : "https://api.github.com/repos/<owner>/<repo>/issues", <1> "url" : "https://api.github.com/repos/<owner>/<repo>/issues", <1>
"body" : "{ "body" : "{
\"title\": \"Found errors in 'contact.html'\", \"title\": \"Found errors in 'contact.html'\",
\"body\": \"Found {{ctx.payload.hits.total.value}} errors in this page in the last 5 minutes\", \"body\": \"Found {{ctx.payload.hits.total}} errors in this page in the last 5 minutes\",
\"assignee\": \"web-admin\", \"assignee\": \"web-admin\",
\"labels\": [ \"bug\", \"sev2\" ] \"labels\": [ \"bug\", \"sev2\" ]
}", }",

View File

@ -107,7 +107,7 @@ You define the condition with the following script:
+ +
[source,text] [source,text]
-------------------------------------------------- --------------------------------------------------
return ctx.payload.hits.total.value > threshold return ctx.payload.hits.total > threshold
-------------------------------------------------- --------------------------------------------------
+ +
If you store the script in a file at `$ES_HOME/config/scripts/threshold_hits.painless`, If you store the script in a file at `$ES_HOME/config/scripts/threshold_hits.painless`,
@ -204,7 +204,7 @@ PUT _watcher/watch/rss_watch
} }
} }
-------------------------------------------------- --------------------------------------------------
// TEST[s/"id" : "threshold_hits"/"source": "return ctx.payload.hits.total.value > params.threshold"/] // TEST[s/"id" : "threshold_hits"/"source": "return ctx.payload.hits.total > params.threshold"/]
<1> Replace `username@example.org` with your email address to receive <1> Replace `username@example.org` with your email address to receive
notifications. notifications.

View File

@ -103,7 +103,7 @@ PUT _watcher/watch/log_error_watch
} }
}, },
"condition" : { "condition" : {
"compare" : { "ctx.payload.hits.total.value" : { "gt" : 0 }} <1> "compare" : { "ctx.payload.hits.total" : { "gt" : 0 }} <1>
} }
} }
-------------------------------------------------- --------------------------------------------------
@ -180,12 +180,12 @@ PUT _watcher/watch/log_error_watch
} }
}, },
"condition" : { "condition" : {
"compare" : { "ctx.payload.hits.total.value" : { "gt" : 0 }} "compare" : { "ctx.payload.hits.total" : { "gt" : 0 }}
}, },
"actions" : { "actions" : {
"log_error" : { "log_error" : {
"logging" : { "logging" : {
"text" : "Found {{ctx.payload.hits.total.value}} errors in the logs" "text" : "Found {{ctx.payload.hits.total}} errors in the logs"
} }
} }
} }

View File

@ -71,7 +71,7 @@ PUT _watcher/watch/log_errors
} }
}, },
"condition" : { <4> "condition" : { <4>
"compare" : { "ctx.payload.hits.total.value" : { "gt" : 5 }} "compare" : { "ctx.payload.hits.total" : { "gt" : 5 }}
}, },
"transform" : { <5> "transform" : { <5>
"search" : { "search" : {
@ -90,13 +90,13 @@ PUT _watcher/watch/log_errors
"host" : "mylisteninghost", "host" : "mylisteninghost",
"port" : 9200, "port" : 9200,
"path" : "/{{watch_id}}", "path" : "/{{watch_id}}",
"body" : "Encountered {{ctx.payload.hits.total.value}} errors" "body" : "Encountered {{ctx.payload.hits.total}} errors"
} }
}, },
"email_administrator" : { "email_administrator" : {
"email" : { "email" : {
"to" : "sys.admino@host.domain", "to" : "sys.admino@host.domain",
"subject" : "Encountered {{ctx.payload.hits.total.value}} errors", "subject" : "Encountered {{ctx.payload.hits.total}} errors",
"body" : "Too many error in the system, see attached data", "body" : "Too many error in the system, see attached data",
"attachments" : { "attachments" : {
"attached_data" : { "attached_data" : {

View File

@ -129,7 +129,7 @@ a condition to check if the search returned more than five hits:
} }
}, },
"condition" : { "condition" : {
"compare" : { "ctx.payload.hits.total.value" : { "gt" : 5 }} "compare" : { "ctx.payload.hits.total" : { "gt" : 5 }}
} }
... ...
} }
@ -142,7 +142,7 @@ Conditions, transforms, and actions can access the search results through the
watch execution context. For example: watch execution context. For example:
* To load all of the search hits into an email body, use `ctx.payload.hits`. * To load all of the search hits into an email body, use `ctx.payload.hits`.
* To reference the total number of hits, use `ctx.payload.hits.total.value`. * To reference the total number of hits, use `ctx.payload.hits.total`.
* To access a particular hit, use its zero-based array index. For example, to * To access a particular hit, use its zero-based array index. For example, to
get the third hit, use `ctx.payload.hits.hits.2`. get the third hit, use `ctx.payload.hits.hits.2`.
* To get a field value from a particular hit, use * To get a field value from a particular hit, use

View File

@ -46,7 +46,7 @@ SearchInput input = new SearchInput(new WatcherSearchTemplateRequest(new String[
watchSourceBuilder.input(input); watchSourceBuilder.input(input);
// Set the condition // Set the condition
watchSourceBuilder.condition(new ScriptCondition(new Script("ctx.payload.hits.total.value > 1"))); watchSourceBuilder.condition(new ScriptCondition(new Script("ctx.payload.hits.total > 1")));
// Create the email template to use for the action // Create the email template to use for the action
EmailTemplate.Builder emailBuilder = EmailTemplate.builder(); EmailTemplate.Builder emailBuilder = EmailTemplate.builder();
@ -78,7 +78,7 @@ PutWatchResponse putWatchResponse2 = watcherClient.preparePutWatch("my-watch")
.filter(rangeQuery("date").gt("{{ctx.trigger.scheduled_time}}")) .filter(rangeQuery("date").gt("{{ctx.trigger.scheduled_time}}"))
.filter(rangeQuery("date").lt("{{ctx.execution_time}}")) .filter(rangeQuery("date").lt("{{ctx.execution_time}}"))
).buildAsBytes()))) ).buildAsBytes())))
.condition(compareCondition("ctx.payload.hits.total.value", CompareCondition.Op.GT, 1L)) .condition(compareCondition("ctx.payload.hits.total", CompareCondition.Op.GT, 1L))
.addAction("email_someone", emailAction(EmailTemplate.builder() .addAction("email_someone", emailAction(EmailTemplate.builder()
.to("someone@domain.host.com") .to("someone@domain.host.com")
.subject("404 recently encountered")))) .subject("404 recently encountered"))))

View File

@ -30,7 +30,7 @@ the other available transforms. For example, you can combine a
} }
}, },
{ {
"script" : "return [ error_count : ctx.payload.hits.total.value ]" <3> "script" : "return [ error_count : ctx.payload.hits.total ]" <3>
} }
] ]
} }