mirror of
https://github.com/elastic/kibana.git
synced 2025-04-23 09:19:04 -04:00
# Backport This will backport the following commits from `main` to `8.9`: - [[DOCS] Edits FormatNumber examples for rule action variables (#161678)](https://github.com/elastic/kibana/pull/161678) <!--- Backport version: 8.9.7 --> ### Questions ? Please refer to the [Backport tool documentation](https://github.com/sqren/backport) <!--BACKPORT [{"author":{"name":"Lisa Cawley","email":"lcawley@elastic.co"},"sourceCommit":{"committedDate":"2023-07-11T17:39:30Z","message":"[DOCS] Edits FormatNumber examples for rule action variables (#161678)","sha":"4ce8b3f4ebb602030ad1a7dbbc999e5128ad3daa","branchLabelMapping":{"^v8.10.0$":"main","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["release_note:skip","Feature:Actions","Team:ResponseOps","docs","backport:prev-minor","v8.9.0","v8.10.0"],"number":161678,"url":"https://github.com/elastic/kibana/pull/161678","mergeCommit":{"message":"[DOCS] Edits FormatNumber examples for rule action variables (#161678)","sha":"4ce8b3f4ebb602030ad1a7dbbc999e5128ad3daa"}},"sourceBranch":"main","suggestedTargetBranches":["8.9"],"targetPullRequestStates":[{"branch":"8.9","label":"v8.9.0","labelRegex":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"state":"NOT_CREATED"},{"branch":"main","label":"v8.10.0","labelRegex":"^v8.10.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/161678","number":161678,"mergeCommit":{"message":"[DOCS] Edits FormatNumber examples for rule action variables (#161678)","sha":"4ce8b3f4ebb602030ad1a7dbbc999e5128ad3daa"}}]}] BACKPORT--> Co-authored-by: Lisa Cawley <lcawley@elastic.co>
This commit is contained in:
parent
e34e8bcd74
commit
047253e4b0
1 changed files with 21 additions and 23 deletions
|
@ -116,14 +116,14 @@ For diagnostic or exploratory purposes, action variables whose values are object
|
|||
|
||||
For situations where your rule response returns arrays of data, you can loop through the `context`:
|
||||
|
||||
[source]
|
||||
[source,sh]
|
||||
--------------------------------------------------
|
||||
{{#context}}{{.}}{{/context}}
|
||||
--------------------------------------------------
|
||||
|
||||
For example, looping through search result hits:
|
||||
|
||||
[source]
|
||||
[source,sh]
|
||||
--------------------------------------------------
|
||||
triggering data was:
|
||||
{{#context.hits}} - {{_source.message}}
|
||||
|
@ -154,7 +154,7 @@ The following capabilities are available:
|
|||
Mustache lambdas provide additional rendering capabilities for Mustache templates.
|
||||
A Mustache lambda is formatted like a Mustache section. For example:
|
||||
|
||||
[source]
|
||||
[source,sh]
|
||||
----
|
||||
{{#EvalMath}} round(context.value, 1) {{/EvalMath}}
|
||||
----
|
||||
|
@ -169,7 +169,7 @@ The EvalMath lambda will evaluate the text passed to it as <<canvas-tinymath-fun
|
|||
|
||||
For example, when the Mustache variable `context.value` is `3.1234`, the following template will render as `3.1`:
|
||||
|
||||
[source]
|
||||
[source,sh]
|
||||
----
|
||||
{{#EvalMath}} round(context.value, 1) {{/EvalMath}}
|
||||
----
|
||||
|
@ -178,7 +178,7 @@ This lambda can access Mustache variables without having to wrap them in `{{}}`.
|
|||
However, if the value is in a string form (for example, an Elasticsearch numeric field whose source was indexed as a string), or could be escaped, escaping the value with triple quotes should allow this to work.
|
||||
For example, if the Mustache variable `context.value` is `"3.1234"`, the following template will render as `3.1`:
|
||||
|
||||
[source]
|
||||
[source,sh]
|
||||
----
|
||||
{{#EvalMath}} round( {{{context.value}}} , 1) {{/EvalMath}}
|
||||
----
|
||||
|
@ -200,7 +200,7 @@ https://hjson.github.io/[Hjson] is a syntax extension to JSON. It has the follow
|
|||
To use it, surround your Hjson content with `{{#ParseHjson}}...{{/ParseHjson}}`.
|
||||
For example:
|
||||
|
||||
[source]
|
||||
[source,sh]
|
||||
----
|
||||
{{#ParseHjson}}
|
||||
{
|
||||
|
@ -234,7 +234,7 @@ The `<date>` parameter is required; the `<time zone>` and `<date format>` parame
|
|||
The default time zone is `"UTC"` and the default date format is `"YYYY-MM-DD hh:mma"`.
|
||||
For example, the following templates all render the same value:
|
||||
|
||||
[source]
|
||||
[source,sh]
|
||||
----
|
||||
{{#FormatDate}} {{{timestamp}}} {{/FormatDate}}
|
||||
{{#FormatDate}} {{{timestamp}}} ; UTC {{/FormatDate}}
|
||||
|
@ -273,19 +273,20 @@ Numbers can be formatted with the following `Intl.NumberFormat` options:
|
|||
To use the lambda, surround the number and formatting options with `{{#FormatNumber}}...{{/FormatNumber}}`.
|
||||
|
||||
The format of the text passed to the lambda is: `<number>; <locales>; <options>`, where semicolons (`;`) separate each parameter.
|
||||
The `<number>` parameter is required. It is the value to be formatted. The `<locales>` and `<options>` parameters are optional, but the semicolons must be provided - the values may be empty strings.
|
||||
The `<locales>` parameter is a list of locales, separated by commas (`,`).
|
||||
The `<options>` parameter is a list of key value pairs, separated by commas (`,`). The key value pairs are strings separated by colons (`:`) where the key is the name of the option and the value is the value of the option.
|
||||
The `<number>` parameter is required; it is the value to be formatted.
|
||||
The `<locales>` and `<options>` parameters are optional, but the semicolons must be provided; the values may be empty strings.
|
||||
The `<locales>` parameter is a list of locales separated by commas (`,`).
|
||||
The `<options>` parameter is a list of key value pairs separated by commas (`,`).
|
||||
The key value pairs are strings separated by colons (`:`) where the key is the name of the option and the value is the value of the option.
|
||||
The default locale is `en-US` and no options are set by default.
|
||||
|
||||
For more information on locale strings, see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl#locales_argument[the `locales` argument documentation from the `Intl` reference].
|
||||
For more information on locale strings, refer to https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl#locales_argument[the `locales` argument documentation from the `Intl` reference].
|
||||
|
||||
The options and values that can be used with them are listed under `options` in the https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/NumberFormat/NumberFormat[Intl.NumberFormat() constructor documentation].
|
||||
|
||||
For example, the following template, given the value of context variable
|
||||
`context.value.condition0` is 628.4, will render as shown below.
|
||||
For example:
|
||||
|
||||
[source]
|
||||
[source,sh]
|
||||
----
|
||||
original value: {{{context.value.condition0}}}
|
||||
formatted value: {{#FormatNumber}}
|
||||
|
@ -293,20 +294,17 @@ For example, the following template, given the value of context variable
|
|||
{{/FormatNumber}}
|
||||
----
|
||||
|
||||
Rendered text:
|
||||
If the context variable `context.value.condition0` has a value of `628.4`, it results in the following text:
|
||||
|
||||
[source]
|
||||
[source,sh]
|
||||
----
|
||||
original value: 628.4
|
||||
formatted value: 628,40 €
|
||||
----
|
||||
|
||||
The `{{FormatNumber}}` and `{{EvalMath}}` lambdas can be used together to perform calculations on numbers and then format them.
|
||||
The `{{FormatNumber}}` and `{{EvalMath}}` lambdas can be used together to perform calculations on numbers and then format them. For example:
|
||||
|
||||
For example, the following template, given the value of context variable
|
||||
`context.value.condition0` is 628.4 will render as shown below.
|
||||
|
||||
[source]
|
||||
[source,sh]
|
||||
----
|
||||
original value: {{{context.value.condition0}}}
|
||||
formatted value: {{#FormatNumber}}
|
||||
|
@ -315,9 +313,9 @@ For example, the following template, given the value of context variable
|
|||
{{/FormatNumber}}
|
||||
----
|
||||
|
||||
Rendered text:
|
||||
If the context variable `context.value.condition0` has a value of `628.4`, it results in the following text:
|
||||
|
||||
[source]
|
||||
[source,sh]
|
||||
----
|
||||
original value: 628.4
|
||||
formatted value: 62,84 €
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue