监视器(Watcher)

class elasticsearch.client.WatcherClient

To use this client, access client.watcher from an Elasticsearch client. For example:

from elasticsearch import Elasticsearch

# Create the client instance
client = Elasticsearch(...)
# Use the watcher client
client.watcher.<method>(...)
ack_watch(*, watch_id, action_id=None, error_trace=None, filter_path=None, human=None, pretty=None)

确认一个监视器。 确认监视器允许您手动节流该监视器动作的执行。

动作的确认状态存储在 status.actions.<id>.ack.state 结构中。

重要提示:如果指定的监视器当前正在执行,此API将返回错误 此行为的原因是为了防止在监视器执行期间覆盖监视器状态。

确认一个动作会节流该动作的后续执行,直到其 ack.state 被重置为 awaits_successful_execution。 当监视器的条件不满足时(条件评估为false)会发生这种情况。 要了解节流在实际中如何工作以及如何为监视器中的单个动作配置节流,请参阅外部文档。

https://www.elastic.co/docs/api/doc/elasticsearch/operation/operation-watcher-ack-watch

Parameters:
  • watch_id (str) – 监视器标识符。

  • action_id (str | Sequence[str] | None) – 要确认的动作标识符的逗号分隔列表。 如果省略此参数,则确认监视器的所有动作。

  • error_trace (bool | None)

  • filter_path (str | Sequence[str] | None)

  • human (bool | None)

  • pretty (bool | None)

Return type:

ObjectApiResponse[Any]

activate_watch(*, watch_id, error_trace=None, filter_path=None, human=None, pretty=None)

激活一个监视器。 监视器可以处于激活或非激活状态。

https://www.elastic.co/docs/api/doc/elasticsearch/operation/operation-watcher-activate-watch

Parameters:
  • watch_id (str) – 监视器标识符。

  • error_trace (bool | None)

  • filter_path (str | Sequence[str] | None)

  • human (bool | None)

  • pretty (bool | None)

Return type:

ObjectApiResponse[Any]

deactivate_watch(*, watch_id, error_trace=None, filter_path=None, human=None, pretty=None)

停用一个监视器。 监视器可以处于激活或非激活状态。

https://www.elastic.co/docs/api/doc/elasticsearch/operation/operation-watcher-deactivate-watch

Parameters:
  • watch_id (str) – 监视器标识符。

  • error_trace (bool | None)

  • filter_path (str | Sequence[str] | None)

  • human (bool | None)

  • pretty (bool | None)

Return type:

ObjectApiResponse[Any]

delete_watch(*, id, error_trace=None, filter_path=None, human=None, pretty=None)

删除一个监视器。 当监视器被移除时,表示该监视器在 .watches 索引中的文档将消失,并且永远不会再次运行。

删除监视器不会从监视历史记录中删除与此监视器相关的任何监视执行记录。

重要提示:删除监视器必须仅使用此API完成。 不要直接使用Elasticsearch删除文档API从 .watches 索引中删除监视器 当启用Elasticsearch安全功能时,确保没有向任何人授予对 .watches 索引的写入权限。

https://www.elastic.co/docs/api/doc/elasticsearch/operation/operation-watcher-delete-watch

Parameters:
Return type:

ObjectApiResponse[Any]

execute_watch(*, id=None, action_modes=None, alternative_input=None, debug=None, error_trace=None, filter_path=None, human=None, ignore_condition=None, pretty=None, record_execution=None, simulated_actions=None, trigger_data=None, watch=None, body=None)

运行一个监视器。 此API可用于在其触发逻辑之外强制执行监视器,或用于调试目的模拟监视器执行。

为了测试和调试目的,您还可以精细控制监视器的运行方式。 您可以运行监视器而不运行其所有动作,或者通过模拟它们来运行。 您还可以通过忽略监视条件来强制执行,并控制监视记录是否在运行后写入监视历史记录。

您可以使用运行监视API通过内联指定监视定义来运行尚未注册的监视器。 这是在将监视器添加到Watcher之前测试和调试监视器的绝佳工具。

当在集群上启用Elasticsearch安全功能时,监视器将以存储监视器的用户的权限运行。 如果您的用户被允许读取索引 a,但不允许读取索引 b,则在执行监视器时将应用完全相同的规则集。

使用运行监视API时,将使用调用API的用户的授权数据作为基础,而不是存储监视器的用户信息。 有关监视执行请求的示例,包括现有、自定义和内联监视器,请参阅外部文档。

https://www.elastic.co/docs/api/doc/elasticsearch/operation/operation-watcher-execute-watch

Parameters:
  • id (str | None) – 监视器标识符。

  • action_modes (Mapping[str, str | Literal['execute', 'force_execute', 'force_simulate', 'simulate', 'skip']] | None) – 确定如何处理监视动作作为监视执行的一部分。

  • alternative_input (Mapping[str, Any] | None) – 当存在时,监视器使用此对象作为有效载荷 而不是执行其自己的输入。

  • debug (bool | None) – 定义监视器是否在调试模式下运行。

  • ignore_condition (bool | None) – 当设置为 true 时,监视执行使用always 条件。这也可以指定为HTTP参数。

  • record_execution (bool | None) – 当设置为 true 时,表示监视执行结果的监视记录 被持久化到当前时间的 .watcher-history 索引中。此外,监视器的状态被更新, 可能会节流后续运行。这也可以指定为HTTP参数。

  • simulated_actions (Mapping[str, Any] | None)

  • trigger_data (Mapping[str, Any] | None) – 此结构被解析为触发器事件的数据 将在监视执行期间使用。

  • watch (Mapping[str, Any] | None) – 当存在时,使用此监视器而不是请求中指定的监视器。 此监视器不会持久化到索引中,且不能设置 record_execution

  • error_trace (bool | None)

  • filter_path (str | Sequence[str] | None)

  • human (bool | None)

  • pretty (bool | None)

  • body (Dict[str, Any] | None)

Return type:

ObjectApiResponse[Any]

get_settings(*, error_trace=None, filter_path=None, human=None, master_timeout=None, pretty=None)

获取 Watcher 索引设置。 获取 Watcher 内部索引 (.watches) 的设置。 仅显示部分设置,例如 index.auto_expand_replicasindex.number_of_replicas

https://www.elastic.co/docs/api/doc/elasticsearch/operation/operation-watcher-get-settings

Parameters:
  • master_timeout (str | Literal[-1] | ~typing.Literal[0] | None) – 等待连接主节点的时间段。 如果在超时前未收到响应,请求将失败并返回错误。

  • error_trace (bool | None)

  • filter_path (str | Sequence[str] | None)

  • human (bool | None)

  • pretty (bool | None)

Return type:

ObjectApiResponse[Any]

get_watch(*, id, error_trace=None, filter_path=None, human=None, pretty=None)

获取一个监视器。

https://www.elastic.co/docs/api/doc/elasticsearch/operation/operation-watcher-get-watch

Parameters:
Return type:

ObjectApiResponse[Any]

put_watch(*, id, actions=None, active=None, condition=None, error_trace=None, filter_path=None, human=None, if_primary_term=None, if_seq_no=None, input=None, metadata=None, pretty=None, throttle_period=None, throttle_period_in_millis=None, transform=None, trigger=None, version=None, body=None)

创建或更新监视器。 当注册监视器时,一个代表该监视器的新文档会被添加到 .watches 索引中,其触发器会立即注册到相关的触发器引擎。 对于 schedule 触发器,调度器通常是触发器引擎。

重要提示:必须使用 Kibana 或此 API 创建监视器。 不要直接使用 Elasticsearch 索引 API 将监视器添加到 .watches 索引。 如果启用了 Elasticsearch 安全功能,不要授予用户对 .watches 索引的写入权限。

添加监视器时,还可以通过设置 active 参数定义其初始激活状态。

当启用 Elasticsearch 安全功能时,监视器只能对存储监视器的用户有权限的索引进行索引或搜索。 如果用户可以读取索引 a 但不能读取索引 b,则在监视器运行时同样适用此限制。

https://www.elastic.co/docs/api/doc/elasticsearch/operation/operation-watcher-put-watch

Parameters:
  • id (str) – 监视器的标识符。

  • actions (Mapping[str, Mapping[str, Any]] | None) – 当条件匹配时将运行的操作列表。

  • active (bool | None) – 监视器的初始状态。默认值为 true,表示监视器默认处于激活状态。

  • condition (Mapping[str, Any] | None) – 定义是否应运行操作的条件。

  • if_primary_term (int | None) – 仅当上次更改监视器的操作具有指定的主术语时才更新监视器

  • if_seq_no (int | None) – 仅当上次更改监视器的操作具有指定的序列号时才更新监视器

  • input (Mapping[str, Any] | None) – 定义加载监视器数据的输入。

  • metadata (Mapping[str, Any] | None) – 将被复制到历史条目中的元数据 JSON。

  • throttle_period (str | Literal[-1] | ~typing.Literal[0] | None) – 操作运行之间的最短时间间隔。默认值为 5 秒。 此默认值可通过配置文件中的 xpack.watcher.throttle.period.default_period 设置更改。 如果同时指定此值和 throttle_period_in_millis 参数,Watcher 将使用请求中包含的最后一个参数。

  • throttle_period_in_millis (Any | None) – 操作运行之间的最短时间间隔(毫秒)。默认为 5000。 如果同时指定此值和 throttle_period 参数,Watcher 将使用请求中包含的最后一个参数。

  • transform (Mapping[str, Any] | None) – 处理监视器有效负载以准备执行监视器操作的转换器。

  • trigger (Mapping[str, Any] | None) – 定义监视器何时运行的触发器。

  • version (int | None) – 用于并发控制的显式版本号

  • error_trace (bool | None)

  • filter_path (str | Sequence[str] | None)

  • human (bool | None)

  • pretty (bool | None)

  • body (Dict[str, Any] | None)

Return type:

ObjectApiResponse[Any]

query_watches(*, error_trace=None, filter_path=None, from_=None, human=None, pretty=None, query=None, search_after=None, size=None, sort=None, body=None)

查询监视器。 以分页方式获取所有已注册的监视器,并可选择通过查询过滤监视器。

注意只有 _idmetadata.* 字段是可查询或可排序的。

https://www.elastic.co/docs/api/doc/elasticsearch/operation/operation-watcher-query-watches

Parameters:
  • from – 从第一个结果开始的偏移量。必须为非负数。

  • query (Mapping[str, Any] | None) – 过滤要返回的监视器的查询。

  • search_after (Sequence[None | bool | float | int | str] | None) – 使用上一页的排序值集合检索下一页命中结果。

  • size (int | None) – 要返回的命中数。必须为非负数。

  • sort (Sequence[str | Mapping[str, Any]] | str | Mapping[str, Any] | None) – 用于排序搜索结果的一个或多个字段。

  • error_trace (bool | None)

  • filter_path (str | Sequence[str] | None)

  • from_ (int | None)

  • human (bool | None)

  • pretty (bool | None)

  • body (Dict[str, Any] | None)

Return type:

ObjectApiResponse[Any]

start(*, error_trace=None, filter_path=None, human=None, master_timeout=None, pretty=None)

启动监视服务。 如果 Watcher 服务尚未运行,则启动它。

https://www.elastic.co/docs/api/doc/elasticsearch/operation/operation-watcher-start

Parameters:
  • master_timeout (str | Literal[-1] | ~typing.Literal[0] | None) – 等待连接主节点的时间段。

  • error_trace (bool | None)

  • filter_path (str | Sequence[str] | None)

  • human (bool | None)

  • pretty (bool | None)

Return type:

ObjectApiResponse[Any]

stats(*, metric=None, emit_stacktraces=None, error_trace=None, filter_path=None, human=None, pretty=None)

获取 Watcher 统计信息。 此 API 始终返回基础指标。 通过使用 metric 参数可获取更多指标。

https://www.elastic.co/docs/api/doc/elasticsearch/operation/operation-watcher-stats

Parameters:
  • metric (Sequence[str | Literal['_all', 'current_watches', 'pending_watches', 'queued_watches']] | str | ~typing.Literal['_all', 'current_watches', 'pending_watches', 'queued_watches'] | None) – 定义响应中包含哪些额外指标。

  • emit_stacktraces (bool | None) – 定义是否为每个正在运行的 watch 生成堆栈跟踪。

  • error_trace (bool | None)

  • filter_path (str | Sequence[str] | None)

  • human (bool | None)

  • pretty (bool | None)

Return type:

ObjectApiResponse[Any]

stop(*, error_trace=None, filter_path=None, human=None, master_timeout=None, pretty=None)

停止 watch 服务。 如果 Watcher 服务正在运行,则停止该服务。

https://www.elastic.co/docs/api/doc/elasticsearch/operation/operation-watcher-stop

Parameters:
  • master_timeout (str | Literal[-1] | ~typing.Literal[0] | None) – 等待主节点的超时时间。如果在超时前主节点不可用, 请求将失败并返回错误。若要表示请求永不超时,请设置为 -1

  • error_trace (bool | None)

  • filter_path (str | Sequence[str] | None)

  • human (bool | None)

  • pretty (bool | None)

Return type:

ObjectApiResponse[Any]

update_settings(*, error_trace=None, filter_path=None, human=None, index_auto_expand_replicas=None, index_number_of_replicas=None, master_timeout=None, pretty=None, timeout=None, body=None)

更新 Watcher 索引设置。 更新 Watcher 内部索引 (.watches) 的设置。 仅允许修改部分设置, 包括 index.auto_expand_replicasindex.number_of_replicasindex.routing.allocation.exclude.*index.routing.allocation.include.*index.routing.allocation.require.*。 修改 index.routing.allocation.include._tier_preference 是例外情况,不允许修改, 因为 Watcher 分片必须始终位于 data_content 层级。

https://www.elastic.co/docs/api/doc/elasticsearch/operation/operation-watcher-update-settings

Parameters:
  • index_auto_expand_replicas (str | None)

  • index_number_of_replicas (int | None)

  • master_timeout (str | Literal[-1] | ~typing.Literal[0] | None) – 等待连接主节点的超时时间。 如果在超时前未收到响应,请求将失败并返回错误。

  • timeout (str | Literal[-1] | ~typing.Literal[0] | None) – 等待响应的超时时间。如果在超时前未收到响应, 请求将失败并返回错误。

  • error_trace (bool | None)

  • filter_path (str | Sequence[str] | None)

  • human (bool | None)

  • pretty (bool | None)

  • body (Dict[str, Any] | None)

Return type:

ObjectApiResponse[Any]