OpenSearch/watcher/docs/reference/condition/array-compare.asciidoc

70 lines
2.8 KiB
Plaintext
Raw Normal View History

Introducing Watch De/activateion Today, once you add a watch to watcher, it's always active. Being "active" means that the watch is registered with the trigger engine (scheduled) and will be executed when its trigger is triggered. Quite often, ppl want to have an option to deactivate/disable a registered watch. Such that while the watch definition still exists in watcher, it is "inactive" and is never triggered. The only way to do this today is using a "hack" where you can change the watch schedule to a cron expression targeting a really far date in the future (say somewhere around 2050). Again.. this is very hackish and it requires changing the actual definition of the watch (you loose its original trigger). This commit introduces the notion of an active/inactive watch.. here are the differences between the two states: - active: the watch is registered with watcher and with the trigger engine and will be executed when its trigger is fired by the engine - inactive: the watch is registered with watcher, but is not registered with the trigger engine. An inactive watch will never be fired, regardless of its trigger. This commit also adds two new APIs: - `_watcher/watch/{id}/_activate` - `_watcher/watch/{id}/_deactivate` to activate and deactivate existing watches. In addition, the Put Watch API now accepts an `active` parameter that indicates the initial state of the put watch (by default set to `true`, i.e. "active"). Closes elastic/elasticsearch#90 Original commit: elastic/x-pack-elasticsearch@37b9ab4d5469f2e5761b55ea7e2dc5955de0283b
2015-09-03 19:55:40 -04:00
[[condition-array-compare]]
==== Array Compare Condition
A watch <<condition, condition>> that compares an array of values in the <<watch-execution-context, Watch Execution Context Model>>
to a given value. The values in the model are identified by a path within that model.
==== Using an Array Compare Condition
The following snippet configures an `array_compare` condition that returns `true` if there is at least one bucket in the
aggregations buckets that has a `doc_count` higher than or equal to 25:
[source,json]
--------------------------------------------------
{
...
"condition": {
"array_compare": {
"ctx.payload.aggregations.top_tweeters.buckets" : { <1>
"path": "doc_count" <2>,
"gte": { <3>
"value": 25, <4>
"quantifier": "some" <5>
}
}
}
}
...
}
--------------------------------------------------
<1> The field name is the path to the array (array path) in the execution context model
<2> The value of the field `path` (here `doc_count`) is the path to the value for each element of the array that the
comparison operator will be applied to
<3> The field name (here `gte`) is the name of the comparison operator
<4> The value of the field `value` in the comparison operator object is the comparison value
<5> The value of the field `quantifier` (`all` or `some`) specifies whether the comparison must be true for all or for
at least one of the values to evaluate the comparison to true
NOTE: The `path` element is optional and will default to `""` if not specified.
NOTE: The `quantifier` element is optional and will default to `"some"` if not specified.
The array path is a "dot-notation" expression that can reference the following variables in the watch context:
[options="header"]
|======
| Name | Description
| `ctx.metadata.*` | Any metadata associated with the watch.
| `ctx.payload.*` | The payload data loaded by the watch's input.
|======
This array path must resolve to an array.
Introducing Watch De/activateion Today, once you add a watch to watcher, it's always active. Being "active" means that the watch is registered with the trigger engine (scheduled) and will be executed when its trigger is triggered. Quite often, ppl want to have an option to deactivate/disable a registered watch. Such that while the watch definition still exists in watcher, it is "inactive" and is never triggered. The only way to do this today is using a "hack" where you can change the watch schedule to a cron expression targeting a really far date in the future (say somewhere around 2050). Again.. this is very hackish and it requires changing the actual definition of the watch (you loose its original trigger). This commit introduces the notion of an active/inactive watch.. here are the differences between the two states: - active: the watch is registered with watcher and with the trigger engine and will be executed when its trigger is fired by the engine - inactive: the watch is registered with watcher, but is not registered with the trigger engine. An inactive watch will never be fired, regardless of its trigger. This commit also adds two new APIs: - `_watcher/watch/{id}/_activate` - `_watcher/watch/{id}/_deactivate` to activate and deactivate existing watches. In addition, the Put Watch API now accepts an `active` parameter that indicates the initial state of the put watch (by default set to `true`, i.e. "active"). Closes elastic/elasticsearch#90 Original commit: elastic/x-pack-elasticsearch@37b9ab4d5469f2e5761b55ea7e2dc5955de0283b
2015-09-03 19:55:40 -04:00
The comparison operator can be any one of the operators supported by the
<<condition-compare-operators, Compare Condition>>.
The quantifier operator can be any one of the following:
[options="header"]
|======
| Name | Description
| `all` | Returns `true` when the resolved value compares `true` according to the comparison operator for all the elements in the array
| `some` | Returns `true` when the resolved value compares `true` according to the comparison operator for at least one element in the array
|======
NOTE: If the array is empty, `all` causes the comparison operator to evaluate to `true` and `some` causes the comparison
operator to evaluate to `false`.
Introducing Watch De/activateion Today, once you add a watch to watcher, it's always active. Being "active" means that the watch is registered with the trigger engine (scheduled) and will be executed when its trigger is triggered. Quite often, ppl want to have an option to deactivate/disable a registered watch. Such that while the watch definition still exists in watcher, it is "inactive" and is never triggered. The only way to do this today is using a "hack" where you can change the watch schedule to a cron expression targeting a really far date in the future (say somewhere around 2050). Again.. this is very hackish and it requires changing the actual definition of the watch (you loose its original trigger). This commit introduces the notion of an active/inactive watch.. here are the differences between the two states: - active: the watch is registered with watcher and with the trigger engine and will be executed when its trigger is fired by the engine - inactive: the watch is registered with watcher, but is not registered with the trigger engine. An inactive watch will never be fired, regardless of its trigger. This commit also adds two new APIs: - `_watcher/watch/{id}/_activate` - `_watcher/watch/{id}/_deactivate` to activate and deactivate existing watches. In addition, the Put Watch API now accepts an `active` parameter that indicates the initial state of the put watch (by default set to `true`, i.e. "active"). Closes elastic/elasticsearch#90 Original commit: elastic/x-pack-elasticsearch@37b9ab4d5469f2e5761b55ea7e2dc5955de0283b
2015-09-03 19:55:40 -04:00
NOTE: It is also possible to use date math expressions and values in the context model as in the <<condition-compare, Compare Condition>>.