索引(Indices)
- class elasticsearch.client.IndicesClient
To use this client, access
client.indicesfrom anElasticsearchclient. For example:from elasticsearch import Elasticsearch # Create the client instance client = Elasticsearch(...) # Use the indices client client.indices.<method>(...)
- add_block(*, index, block, allow_no_indices=None, error_trace=None, expand_wildcards=None, filter_path=None, human=None, ignore_unavailable=None, master_timeout=None, pretty=None, timeout=None)
添加索引块。
向索引添加一个索引块。 索引块通过限制特定操作类型来控制对索引的操作权限。
https://www.elastic.co/docs/api/doc/elasticsearch/operation/operation-indices-add-block
- Parameters:
index (str) – 用于限制请求的索引名称逗号分隔列表或通配符表达式。 默认情况下必须显式指定要添加块的索引名称。若需允许对 _all、* 等通配符表达式添加块, 需将 action.destructive_requires_name 设置为 false。可通过 elasticsearch.yml 文件或集群更新设置 API 修改此配置。
block (str | Literal['metadata', 'read', 'read_only', 'write']) – 要添加到索引的块类型。
allow_no_indices (bool | None) – 若为 false,当通配符表达式、索引别名或 _all 值仅指向缺失/关闭的索引时, 请求将返回错误。即使请求同时指向其他开启的索引也适用此规则。例如,指向 foo*,bar* 的请求 若存在以 foo 开头的索引但无 bar 开头的索引,则会报错。
expand_wildcards (Sequence[str | Literal['all', 'closed', 'hidden', 'none', 'open']] | str | ~typing.Literal['all', 'closed', 'hidden', 'none', 'open'] | None) – 通配符可匹配的索引类型。若请求可针对数据流,此参数决定通配符表达式 是否匹配隐藏数据流。支持逗号分隔值如 open,hidden。
ignore_unavailable (bool | None) – 若为 false,当请求指向缺失或关闭的索引时将返回错误。
master_timeout (str | Literal[-1] | ~typing.Literal[0] | None) – 等待主节点的超时时间。若在超时前主节点不可用,请求将失败并返回错误。 可设置为 -1 表示永不超时。
timeout (str | Literal[-1] | ~typing.Literal[0] | None) – 更新集群元数据后等待集群中所有相关节点响应的超时时间。若超时前未收到响应, 集群元数据更新仍会生效但响应会表明未完全确认。可设置为 -1 表示永不超时。
error_trace (bool | None)
human (bool | None)
pretty (bool | None)
- Return type:
- analyze(*, index=None, analyzer=None, attributes=None, char_filter=None, error_trace=None, explain=None, field=None, filter=None, filter_path=None, human=None, normalizer=None, pretty=None, text=None, tokenizer=None, body=None)
获取文本分析生成的词元。
分析 API 对文本字符串执行分析并返回生成的词元。
生成过多词元可能导致节点内存不足。
index.analyze.max_token_count设置可限制生成的词元数量。 若超过此限制将报错。未指定索引的_analyze端点始终使用10000作为限制值。https://www.elastic.co/docs/api/doc/elasticsearch/operation/operation-indices-analyze
- Parameters:
index (str | None) – 用于派生分析器的索引。若指定,analyzer 或字段参数会覆盖此值。 若未指定索引或索引无默认分析器,则使用标准分析器。
analyzer (str | None) – 应用于给定文本的分析器名称。可以是内置分析器或索引中配置的分析器。
attributes (Sequence[str] | None) – 用于过滤 explain 参数输出的词元属性数组。
char_filter (Sequence[str | Mapping[str, Any]] | None) – 在分词器前预处理字符的字符过滤器数组。
explain (bool | None) – 若为 true,响应包含词元属性和额外详细信息。
field (str | None) – 用于派生分析器的字段。使用此参数必须指定索引。若指定,analyzer 参数会覆盖此值。
filter (Sequence[str | Mapping[str, Any]] | None) – 在分词器后应用的词元过滤器数组。
normalizer (str | None) – 用于将文本转换为单个词元的规范化器。
text (str | Sequence[str] | None) – 待分析文本。若提供字符串数组,则作为多值字段分析。
tokenizer (str | Mapping[str, Any] | None) – 用于将文本转换为词元的分词器。
error_trace (bool | None)
human (bool | None)
pretty (bool | None)
- Return type:
- cancel_migrate_reindex(*, index, error_trace=None, filter_path=None, human=None, pretty=None)
取消迁移重索引操作。
取消对数据流或索引的迁移重索引尝试。
https://www.elastic.co/docs/api/doc/elasticsearch/operation/operation-indices-cancel-migrate-reindex
- clear_cache(*, index=None, allow_no_indices=None, error_trace=None, expand_wildcards=None, fielddata=None, fields=None, filter_path=None, human=None, ignore_unavailable=None, pretty=None, query=None, request=None)
清除缓存。
清除一个或多个索引的缓存。 对于数据流,API 会清除其后备索引的缓存。
默认清除所有缓存。 如需清除特定缓存,使用
fielddata、query或request参数。 若只需清除特定字段的缓存,使用fields参数。https://www.elastic.co/docs/api/doc/elasticsearch/operation/operation-indices-clear-cache
- Parameters:
index (str | Sequence[str] | None) – 用于限制请求的数据流、索引和别名逗号分隔列表。支持通配符 (*)。 若要针对所有数据流和索引,可省略此参数或使用 * 或 _all。
allow_no_indices (bool | None) – 若为 false,当通配符表达式、索引别名或 _all 值仅指向缺失/关闭的索引时, 请求将返回错误。即使请求同时指向其他开启的索引也适用此规则。
expand_wildcards (Sequence[str | Literal['all', 'closed', 'hidden', 'none', 'open']] | str | ~typing.Literal['all', 'closed', 'hidden', 'none', 'open'] | None) – 通配符可匹配的索引类型。若请求可针对数据流,此参数决定通配符表达式 是否匹配隐藏数据流。支持逗号分隔值如 open,hidden。
fielddata (bool | None) – 若为 true,清除字段缓存。使用 fields 参数可仅清除特定字段的缓存。
fields (str | Sequence[str] | None) – 用于限制 fielddata 参数的字段名称逗号分隔列表。
ignore_unavailable (bool | None) – 若为 false,当请求指向缺失或关闭的索引时将返回错误。
query (bool | None) – 若为 true,清除查询缓存。
request (bool | None) – 若为 true,清除请求缓存。
error_trace (bool | None)
human (bool | None)
pretty (bool | None)
- Return type:
- clone(*, index, target, aliases=None, error_trace=None, filter_path=None, human=None, master_timeout=None, pretty=None, settings=None, timeout=None, wait_for_active_shards=None, body=None)
克隆索引。
将现有索引克隆为新索引。 每个原始主分片会被克隆为新索引中的新主分片。
重要提示:Elasticsearch 不会对结果索引应用索引模板。 该 API 也不会从原始索引复制索引元数据。 索引元数据包括别名、索引生命周期管理阶段定义和跨集群复制 (CCR) 跟随者信息。 例如克隆 CCR 跟随者索引时,结果克隆索引不会成为跟随者索引。
克隆 API 会将大部分索引设置从源索引复制到结果索引,但
index.number_of_replicas和index.auto_expand_replicas除外。 需在克隆请求中配置这些设置来设定结果索引的副本数。克隆过程如下:
- 首先创建与源索引定义相同的新目标索引
- 然后从源索引硬链接段到目标索引。若文件系统不支持硬链接,则所有段会被复制到新索引(耗时更长)
- 最后像恢复刚重新打开的关闭索引一样恢复目标索引
重要提示:只有满足以下条件的索引才能被克隆:
- 索引必须标记为只读且集群健康状态为 green
- 目标索引必须不存在
- 源索引与目标索引的主分片数量必须相同
- 处理克隆过程的节点需有足够磁盘空间容纳索引的第二个副本
数据流的当前写入索引不能被克隆。 要克隆当前写入索引,需先滚动数据流以创建新写入索引,然后才能克隆之前的写入索引。
注意:不能在
_clone请求中指定映射。目标索引将使用源索引的映射。监控克隆过程
可通过 cat recovery API 监控克隆过程,或使用集群健康 API 并通过设置
wait_for_status为yellow来等待所有主分片分配完成。_cloneAPI 在目标索引加入集群状态后立即返回,此时尚未分配任何分片。 所有分片处于未分配状态。 若因任何原因无法分配目标索引,其主分片将保持未分配状态直到能在该节点分配。一旦主分片分配完成,会进入初始化状态并开始克隆过程。 克隆操作完成后分片变为活跃状态。 此时 Elasticsearch 会尝试分配副本并可能决定将主分片重定位到其他节点。
等待活跃分片
由于克隆操作会创建新索引来克隆分片,索引创建时的等待活跃分片设置同样适用于克隆索引操作。
https://www.elastic.co/docs/api/doc/elasticsearch/operation/operation-indices-clone
- Parameters:
index (str) – 要克隆的源索引名称。
target (str) – 要创建的目标索引名称。
master_timeout (str | Literal[-1] | ~typing.Literal[0] | None) – 等待连接主节点的超时时间。若超时前未收到响应,请求将失败并返回错误。
timeout (str | Literal[-1] | ~typing.Literal[0] | None) – 等待响应的超时时间。若超时前未收到响应,请求将失败并返回错误。
wait_for_active_shards (int | str | Literal['all', 'index-setting'] | None) – 执行操作前必须活跃的分片副本数。可设为 all 或不超过索引总分片数 (number_of_replicas+1) 的正整数。
error_trace (bool | None)
human (bool | None)
pretty (bool | None)
- Return type:
- close(*, index, allow_no_indices=None, error_trace=None, expand_wildcards=None, filter_path=None, human=None, ignore_unavailable=None, master_timeout=None, pretty=None, timeout=None, wait_for_active_shards=None)
关闭一个索引。 已关闭的索引会阻止读写操作,并且不允许开放索引所允许的所有操作。 无法在已关闭的索引中索引文档或搜索文档。 关闭的索引无需维护用于索引或搜索文档的内部数据结构,从而减少集群的开销。
当打开或关闭索引时,主节点负责重新启动索引分片以反映索引的新状态。 然后分片将经历正常的恢复过程。 集群会自动复制已打开和已关闭索引的数据,以确保始终安全地保留足够的分片副本。
您可以同时打开或关闭多个索引。 如果请求显式引用缺失的索引,则会抛出错误。 可以通过使用
ignore_unavailable=true参数来关闭此行为。默认情况下,必须明确指定要打开或关闭的索引名称。 要使用
_all、*或其他通配符表达式打开或关闭索引,请将action.destructive_requires_name设置更改为false。也可以通过集群更新设置 API 更改此设置。已关闭的索引会消耗大量磁盘空间,这可能导致托管环境出现问题。 可以通过集群设置 API 将
cluster.indices.close.enable设置为false来禁用关闭索引功能。https://www.elastic.co/docs/api/doc/elasticsearch/operation/operation-indices-close
- Parameters:
allow_no_indices (bool | None) – 如果为 false,当任何通配符表达式、索引别名或 _all 值仅指向缺失或已关闭的索引时,请求将返回错误。 即使请求同时针对其他开放索引,此行为也适用。
expand_wildcards (Sequence[str | Literal['all', 'closed', 'hidden', 'none', 'open']] | str | ~typing.Literal['all', 'closed', 'hidden', 'none', 'open'] | None) – 通配符模式可匹配的索引类型。如果请求可以针对数据流,此参数决定通配符表达式是否匹配隐藏的数据流。 支持逗号分隔的值,例如 open,hidden。
ignore_unavailable (bool | None) – 如果为 false,当请求针对缺失或已关闭的索引时,将返回错误。
master_timeout (str | Literal[-1] | ~typing.Literal[0] | None) – 等待连接到主节点的时间。如果在超时前未收到响应,请求将失败并返回错误。
timeout (str | Literal[-1] | ~typing.Literal[0] | None) – 等待响应的时间。如果在超时前未收到响应,请求将失败并返回错误。
wait_for_active_shards (int | str | Literal['all', 'index-setting'] | None) – 执行操作前必须激活的分片副本数量。可设置为 all 或任何不超过索引总分片数的正整数(number_of_replicas+1)。
error_trace (bool | None)
human (bool | None)
pretty (bool | None)
- Return type:
- create(*, index, aliases=None, error_trace=None, filter_path=None, human=None, mappings=None, master_timeout=None, pretty=None, settings=None, timeout=None, wait_for_active_shards=None, body=None)
创建一个索引。 您可以使用创建索引 API 向 Elasticsearch 集群添加新索引。 创建索引时,可以指定以下内容:
- 索引的设置
- 索引中字段的映射
- 索引别名
等待活动分片
默认情况下,只有当每个分片的主副本都已启动或请求超时时,索引创建才会向客户端返回响应。 索引创建响应将指示发生了什么。 例如,
acknowledged表示索引是否在集群中成功创建,而shards_acknowledged表示在超时前是否已为索引中的每个分片启动了所需数量的分片副本。 请注意,即使acknowledged或shards_acknowledged为false,索引创建仍可能成功。 这些值仅表示操作是否在超时前完成。 如果acknowledged为 false,表示在集群状态更新为新创建的索引之前请求已超时,但索引很可能很快就会创建。 如果shards_acknowledged为 false,则表示在启动所需数量的分片(默认为仅主分片)之前请求已超时,即使集群状态已成功更新以反映新创建的索引(即acknowledged为true)。您可以通过索引设置
index.write.wait_for_active_shards更改仅等待主分片启动的默认行为。 请注意,更改此设置也会影响所有后续写操作的wait_for_active_shards值。https://www.elastic.co/docs/api/doc/elasticsearch/operation/operation-indices-create
- Parameters:
index (str) – 要创建的索引名称。索引名称必须满足以下条件: * 仅小写字母 * 不能包含 `、/、`*、?、”、<、>、|、空格字符、, 或 # * 7.0 之前的索引可以包含冒号(:),但已弃用且后续版本不再支持 * 不能以 -、_ 或 + 开头 * 不能是 . 或 .. * 长度不能超过 255 字节(注意是字节,因此多字节字符会更快达到限制) * 以 . 开头的名称已弃用,插件管理的隐藏索引和内部索引除外
mappings (Mapping[str, Any] | None) – 索引中字段的映射。如果指定,此映射可以包含: - 字段名称 - 字段数据类型 - 映射参数
master_timeout (str | Literal[-1] | ~typing.Literal[0] | None) – 等待连接到主节点的时间。如果在超时前未收到响应,请求将失败并返回错误。
timeout (str | Literal[-1] | ~typing.Literal[0] | None) – 等待响应的时间。如果在超时前未收到响应,请求将失败并返回错误。
wait_for_active_shards (int | str | Literal['all', 'index-setting'] | None) – 执行操作前必须激活的分片副本数量。可设置为 all 或任何不超过索引总分片数的正整数(number_of_replicas+1)。
error_trace (bool | None)
human (bool | None)
pretty (bool | None)
- Return type:
- create_data_stream(*, name, error_trace=None, filter_path=None, human=None, master_timeout=None, pretty=None, timeout=None)
创建一个数据流。
您必须具有启用了数据流功能的匹配索引模板。
https://www.elastic.co/docs/api/doc/elasticsearch/operation/operation-indices-create-data-stream
- Parameters:
name (str) – 数据流名称,必须满足以下条件: 仅小写字母;不能包含 `、/、`*、?、”、<、>、|、,、#、: 或空格字符; 不能以 -、_、+ 或 .ds- 开头;不能是 . 或 ..; 长度不能超过 255 字节。多字节字符会更快达到此限制。
master_timeout (str | Literal[-1] | ~typing.Literal[0] | None) – 等待连接到主节点的时间。如果在超时前未收到响应,请求将失败并返回错误。
timeout (str | Literal[-1] | ~typing.Literal[0] | None) – 等待响应的时间。如果在超时前未收到响应,请求将失败并返回错误。
error_trace (bool | None)
human (bool | None)
pretty (bool | None)
- Return type:
- create_from(*, source, dest, create_from=None, body=None, error_trace=None, filter_path=None, human=None, pretty=None)
从源索引创建新索引。
将源索引的映射和设置复制到目标索引,同时允许请求设置和映射覆盖源值。
https://www.elastic.co/docs/api/doc/elasticsearch/operation/operation-indices-create-from
- data_streams_stats(*, name=None, error_trace=None, expand_wildcards=None, filter_path=None, human=None, pretty=None)
获取数据流统计信息。
获取一个或多个数据流的统计信息。
https://www.elastic.co/docs/api/doc/elasticsearch/operation/operation-indices-data-streams-stats-1
- Parameters:
name (str | None) – 用于限制请求的逗号分隔的数据流列表。支持通配符表达式(*)。 要针对集群中的所有数据流,请省略此参数或使用 *。
expand_wildcards (Sequence[str | Literal['all', 'closed', 'hidden', 'none', 'open']] | str | ~typing.Literal['all', 'closed', 'hidden', 'none', 'open'] | None) – 通配符模式可匹配的数据流类型。支持逗号分隔的值,例如 open,hidden。
error_trace (bool | None)
human (bool | None)
pretty (bool | None)
- Return type:
- delete(*, index, allow_no_indices=None, error_trace=None, expand_wildcards=None, filter_path=None, human=None, ignore_unavailable=None, master_timeout=None, pretty=None, timeout=None)
删除索引。 删除索引会同时删除其文档、分片和元数据。 但不会删除相关的 Kibana 组件,如数据视图、可视化或仪表板。
不能删除数据流的当前写入索引。 要删除索引,必须先滚动更新数据流以创建新的写入索引。 然后才能使用删除索引API删除之前的写入索引。
https://www.elastic.co/docs/api/doc/elasticsearch/operation/operation-indices-delete
- Parameters:
index (str | Sequence[str]) – 要删除的索引逗号分隔列表。不能指定索引别名。 默认情况下,此参数不支持通配符(*)或`_all`。 要使用通配符或`_all`,需将集群设置`action.destructive_requires_name`设为`false`。
allow_no_indices (bool | None) – 如果为`false`,当任何通配符表达式、索引别名或`_all`值 仅指向缺失或关闭的索引时,请求将返回错误。即使请求同时指向其他打开的索引也适用此行为。
expand_wildcards (Sequence[str | Literal['all', 'closed', 'hidden', 'none', 'open']] | str | ~typing.Literal['all', 'closed', 'hidden', 'none', 'open'] | None) – 通配符可匹配的索引类型。如果请求可以针对数据流, 此参数决定通配符表达式是否匹配隐藏数据流。支持逗号分隔值,如`open,hidden`。
ignore_unavailable (bool | None) – 如果为`false`,当请求指向缺失或关闭的索引时将返回错误。
master_timeout (str | Literal[-1] | ~typing.Literal[0] | None) – 等待连接主节点的超时时间。如果在超时前未收到响应, 请求将失败并返回错误。
timeout (str | Literal[-1] | ~typing.Literal[0] | None) – 等待响应的超时时间。如果在超时前未收到响应, 请求将失败并返回错误。
error_trace (bool | None)
human (bool | None)
pretty (bool | None)
- Return type:
- delete_alias(*, index, name, error_trace=None, filter_path=None, human=None, master_timeout=None, pretty=None, timeout=None)
删除别名。 从别名中移除数据流或索引。
https://www.elastic.co/docs/api/doc/elasticsearch/operation/operation-indices-delete-alias
- Parameters:
name (str | Sequence[str]) – 要移除的别名逗号分隔列表。支持通配符(*)。 要移除所有别名,可使用`*`或`_all`。
master_timeout (str | Literal[-1] | ~typing.Literal[0] | None) – 等待连接主节点的超时时间。如果在超时前未收到响应, 请求将失败并返回错误。
timeout (str | Literal[-1] | ~typing.Literal[0] | None) – 等待响应的超时时间。如果在超时前未收到响应, 请求将失败并返回错误。
error_trace (bool | None)
human (bool | None)
pretty (bool | None)
- Return type:
- delete_data_lifecycle(*, name, error_trace=None, expand_wildcards=None, filter_path=None, human=None, master_timeout=None, pretty=None, timeout=None)
删除数据流生命周期。 移除数据流的生命周期配置,使其不再受数据流生命周期管理。
https://www.elastic.co/docs/api/doc/elasticsearch/operation/operation-indices-delete-data-lifecycle
- Parameters:
expand_wildcards (Sequence[str | Literal['all', 'closed', 'hidden', 'none', 'open']] | str | ~typing.Literal['all', 'closed', 'hidden', 'none', 'open'] | None) – 通配符表达式是否应扩展到打开或关闭的索引(默认: open)
master_timeout (str | Literal[-1] | ~typing.Literal[0] | None) – 指定连接主节点的超时时间
timeout (str | Literal[-1] | ~typing.Literal[0] | None) – 文档的显式时间戳
error_trace (bool | None)
human (bool | None)
pretty (bool | None)
- Return type:
- delete_data_stream(*, name, error_trace=None, expand_wildcards=None, filter_path=None, human=None, master_timeout=None, pretty=None)
删除数据流。 删除一个或多个数据流及其后备索引。
https://www.elastic.co/docs/api/doc/elasticsearch/operation/operation-indices-delete-data-stream
- Parameters:
expand_wildcards (Sequence[str | Literal['all', 'closed', 'hidden', 'none', 'open']] | str | ~typing.Literal['all', 'closed', 'hidden', 'none', 'open'] | None) – 通配符可匹配的数据流类型。 支持逗号分隔值,如`open,hidden`。
master_timeout (str | Literal[-1] | ~typing.Literal[0] | None) – 等待连接主节点的超时时间。如果在超时前未收到响应, 请求将失败并返回错误。
error_trace (bool | None)
human (bool | None)
pretty (bool | None)
- Return type:
- delete_data_stream_options(*, name, error_trace=None, expand_wildcards=None, filter_path=None, human=None, master_timeout=None, pretty=None, timeout=None)
删除数据流选项。 移除数据流的配置选项。
https://www.elastic.co/guide/en/elasticsearch/reference/master/index.html
- Parameters:
expand_wildcards (Sequence[str | Literal['all', 'closed', 'hidden', 'none', 'open']] | str | ~typing.Literal['all', 'closed', 'hidden', 'none', 'open'] | None) – 通配符表达式是否应扩展到打开或关闭的索引(默认: open)
master_timeout (str | Literal[-1] | ~typing.Literal[0] | None) – 指定连接主节点的超时时间
timeout (str | Literal[-1] | ~typing.Literal[0] | None) – 文档的显式时间戳
error_trace (bool | None)
human (bool | None)
pretty (bool | None)
- Return type:
- delete_index_template(*, name, error_trace=None, filter_path=None, human=None, master_timeout=None, pretty=None, timeout=None)
删除索引模板。 提供的 可以包含多个用逗号分隔的模板名称。如果指定了多个模板名称,则不支持通配符,且提供的名称应与现有模板完全匹配。
https://www.elastic.co/docs/api/doc/elasticsearch/operation/operation-indices-delete-index-template
- Parameters:
name (str | Sequence[str]) – 用于限制请求的索引模板名称的逗号分隔列表。 支持通配符 (*) 表达式。
master_timeout (str | Literal[-1] | ~typing.Literal[0] | None) – 等待连接到主节点的时间段。如果 在超时到期前未收到响应,请求将失败并 返回错误。
timeout (str | Literal[-1] | ~typing.Literal[0] | None) – 等待响应的时间段。如果在超时到期前 未收到响应,请求将失败并返回错误。
error_trace (bool | None)
human (bool | None)
pretty (bool | None)
- Return type:
- delete_template(*, name, error_trace=None, filter_path=None, human=None, master_timeout=None, pretty=None, timeout=None)
删除旧版索引模板。 重要说明:此文档涉及已弃用的旧版索引模板,它们将被 Elasticsearch 7.8 引入的可组合模板取代。
https://www.elastic.co/docs/api/doc/elasticsearch/operation/operation-indices-delete-template
- Parameters:
name (str) – 要删除的旧版索引模板名称。支持通配符 (*) 表达式。
master_timeout (str | Literal[-1] | ~typing.Literal[0] | None) – 等待连接到主节点的时间段。如果 在超时到期前未收到响应,请求将失败并 返回错误。
timeout (str | Literal[-1] | ~typing.Literal[0] | None) – 等待响应的时间段。如果在超时到期前 未收到响应,请求将失败并返回错误。
error_trace (bool | None)
human (bool | None)
pretty (bool | None)
- Return type:
- disk_usage(*, index, allow_no_indices=None, error_trace=None, expand_wildcards=None, filter_path=None, flush=None, human=None, ignore_unavailable=None, pretty=None, run_expensive_tasks=None)
分析索引磁盘使用情况。 分析索引或数据流中每个字段的磁盘使用情况。 此 API 可能不支持在旧版 Elasticsearch 中创建的索引。 小型索引的结果可能不准确,因为 API 可能不会分析索引的某些部分。
注意:响应中分析的索引分片字段总大小通常小于索引的
store_size值,因为忽略了一些小型元数据文件,且 API 可能未扫描数据文件的某些部分。 由于存储字段以压缩格式存储在一起,存储字段的大小也是估计值,可能不准确。_id字段的存储大小可能被低估,而_source字段则被高估。https://www.elastic.co/docs/api/doc/elasticsearch/operation/operation-indices-disk-usage
- Parameters:
index (str | Sequence[str]) – 用于限制请求的数据流、索引和别名的逗号分隔列表。 建议使用单个索引(或数据流的最新后备索引)执行此 API,因为 API 会显著消耗资源。
allow_no_indices (bool | None) – 如果为 false,当任何通配符表达式、索引别名或 _all 值仅指向缺失或关闭的索引时,请求将返回错误。 即使请求针对其他打开的索引,此行为也适用。例如,针对 foo*,bar* 的请求如果存在以 foo 开头的索引但没有以 bar 开头的索引,将返回错误。
expand_wildcards (Sequence[str | Literal['all', 'closed', 'hidden', 'none', 'open']] | str | ~typing.Literal['all', 'closed', 'hidden', 'none', 'open'] | None) – 通配符模式可以匹配的索引类型。如果请求可以针对数据流,此参数决定通配符表达式是否匹配隐藏的数据流。支持逗号分隔的值,如 open,hidden。
flush (bool | None) – 如果为 true,API 在分析前执行刷新。如果为 false,响应可能不包含未提交的数据。
ignore_unavailable (bool | None) – 如果为 true,响应中不包含缺失或关闭的索引。
run_expensive_tasks (bool | None) – 分析字段磁盘使用情况是资源密集型操作。要使用此 API,必须将此参数设置为 true。
error_trace (bool | None)
human (bool | None)
pretty (bool | None)
- Return type:
- downsample(*, index, target_index, config=None, body=None, error_trace=None, filter_path=None, human=None, pretty=None)
对索引进行降采样。 聚合时间序列 (TSDS) 索引,并按配置的时间间隔分组存储每个指标字段的预计算统计摘要(
min、max、sum、value_count和avg)。 例如,包含每 10 秒采样一次指标的 TSDS 索引可以降采样为每小时索引。 一小时间隔内的所有文档将被汇总并存储为降采样索引中的单个文档。注意:仅支持时间序列数据流中的索引。 源索引上不能定义字段或文档级别的安全性。 源索引必须为只读(
index.blocks.write: true)。https://www.elastic.co/docs/api/doc/elasticsearch/operation/operation-indices-downsample
- exists(*, index, allow_no_indices=None, error_trace=None, expand_wildcards=None, filter_path=None, flat_settings=None, human=None, ignore_unavailable=None, include_defaults=None, local=None, pretty=None)
检查索引。 检查一个或多个索引、索引别名或数据流是否存在。
https://www.elastic.co/docs/api/doc/elasticsearch/operation/operation-indices-exists
- Parameters:
allow_no_indices (bool | None) – 如果为 false,当任何通配符表达式、索引别名或 _all 值仅指向缺失或关闭的索引时,请求将返回错误。 即使请求针对其他打开的索引,此行为也适用。
expand_wildcards (Sequence[str | Literal['all', 'closed', 'hidden', 'none', 'open']] | str | ~typing.Literal['all', 'closed', 'hidden', 'none', 'open'] | None) – 通配符模式可以匹配的索引类型。如果请求可以针对数据流,此参数决定通配符表达式是否匹配隐藏的数据流。支持逗号分隔的值,如 open,hidden。
flat_settings (bool | None) – 如果为 true,以扁平格式返回设置。
ignore_unavailable (bool | None) – 如果为 false,当请求针对缺失或关闭的索引时,将返回错误。
include_defaults (bool | None) – 如果为 true,在响应中返回所有默认设置。
local (bool | None) – 如果为 true,请求仅从本地节点检索信息。
error_trace (bool | None)
human (bool | None)
pretty (bool | None)
- Return type:
- exists_alias(*, name, index=None, allow_no_indices=None, error_trace=None, expand_wildcards=None, filter_path=None, human=None, ignore_unavailable=None, master_timeout=None, pretty=None)
检查别名。
检查一个或多个数据流或索引别名是否存在。
https://www.elastic.co/docs/api/doc/elasticsearch/operation/operation-indices-exists-alias
- Parameters:
index (str | Sequence[str] | None) – 用于限制请求的数据流或索引列表,以逗号分隔。支持通配符 (*)。若要针对所有数据流和索引,请省略此参数或使用 * 或 _all。
allow_no_indices (bool | None) – 如果为 false,当任何通配符表达式、索引别名或 _all 值仅指向缺失或关闭的索引时,请求将返回错误。即使请求针对其他打开的索引,此行为也适用。
expand_wildcards (Sequence[str | Literal['all', 'closed', 'hidden', 'none', 'open']] | str | ~typing.Literal['all', 'closed', 'hidden', 'none', 'open'] | None) – 通配符模式可以匹配的索引类型。如果请求可以针对数据流,此参数决定通配符表达式是否匹配隐藏的数据流。支持逗号分隔的值,例如 open,hidden。
ignore_unavailable (bool | None) – 如果为 false,当目标索引或数据流中包含缺失的数据流或索引时,请求将返回错误。
master_timeout (str | Literal[-1] | ~typing.Literal[0] | None) – 等待连接到主节点的时间。如果在超时前未收到响应,请求将失败并返回错误。
error_trace (bool | None)
human (bool | None)
pretty (bool | None)
- Return type:
- exists_index_template(*, name, error_trace=None, filter_path=None, flat_settings=None, human=None, local=None, master_timeout=None, pretty=None)
检查索引模板。
检查索引模板是否存在。
https://www.elastic.co/docs/api/doc/elasticsearch/operation/operation-indices-exists-index-template
- Parameters:
name (str) – 用于限制请求的索引模板名称列表,以逗号分隔。支持通配符 (*) 表达式。
flat_settings (bool | None) – 如果为 true,以扁平格式返回设置。
local (bool | None) – 如果为 true,请求仅从本地节点获取信息。默认为 false,表示从主节点获取信息。
master_timeout (str | Literal[-1] | ~typing.Literal[0] | None) – 等待连接到主节点的时间。如果在超时前未收到响应,请求将失败并返回错误。
error_trace (bool | None)
human (bool | None)
pretty (bool | None)
- Return type:
- exists_template(*, name, error_trace=None, filter_path=None, flat_settings=None, human=None, local=None, master_timeout=None, pretty=None)
检查索引模板是否存在。 获取关于索引模板是否存在的信息。 索引模板定义了可以自动应用到新索引的设置、映射和别名。
重要说明:此文档涉及传统索引模板,这些模板已被弃用,并将被 Elasticsearch 7.8 中引入的可组合模板取代。
https://www.elastic.co/docs/api/doc/elasticsearch/operation/operation-indices-exists-template
- Parameters:
name (str | Sequence[str]) – 用于限制请求的索引模板名称列表,以逗号分隔。支持通配符 (*) 表达式。
flat_settings (bool | None) – 指示是否使用扁平格式的响应。
local (bool | None) – 指示是否仅从本地节点获取信息。
master_timeout (str | Literal[-1] | ~typing.Literal[0] | None) – 等待主节点的时间。如果主节点在超时前不可用,请求将失败并返回错误。若要表示请求永不超时,请设置为 -1。
error_trace (bool | None)
human (bool | None)
pretty (bool | None)
- Return type:
- explain_data_lifecycle(*, index, error_trace=None, filter_path=None, human=None, include_defaults=None, master_timeout=None, pretty=None)
获取数据流生命周期的状态。 获取索引或数据流当前数据流生命周期状态的信息,例如自索引创建以来的时间、自滚动以来的时间、管理索引的生命周期配置,或在生命周期执行期间遇到的任何错误。
https://www.elastic.co/docs/api/doc/elasticsearch/operation/operation-indices-explain-data-lifecycle
- Parameters:
- Return type:
- field_usage_stats(*, index, allow_no_indices=None, error_trace=None, expand_wildcards=None, fields=None, filter_path=None, human=None, ignore_unavailable=None, pretty=None)
获取字段使用统计。 获取索引的每个分片和字段的字段使用信息。 当查询在集群上运行时,字段使用统计会自动捕获。 一个访问给定字段的分片级搜索请求,即使在该请求中多次访问,也只计为一次使用。
响应体报告索引中支持字段的数据结构的每个分片使用计数。 即使请求多次访问同一字段,给定请求对每个计数的最大增量值也为 1。
https://www.elastic.co/docs/api/doc/elasticsearch/operation/operation-indices-field-usage-stats
- Parameters:
allow_no_indices (bool | None) – 如果为 false,当任何通配符表达式、索引别名或 _all 值仅指向缺失或关闭的索引时,请求将返回错误。即使请求针对其他打开的索引,此行为也适用。例如,针对 foo*,bar* 的请求,如果存在以 foo 开头的索引但没有以 bar 开头的索引,将返回错误。
expand_wildcards (Sequence[str | Literal['all', 'closed', 'hidden', 'none', 'open']] | str | ~typing.Literal['all', 'closed', 'hidden', 'none', 'open'] | None) – 通配符模式可以匹配的索引类型。如果请求可以针对数据流,此参数决定通配符表达式是否匹配隐藏的数据流。支持逗号分隔的值,例如 open,hidden。
fields (str | Sequence[str] | None) – 要包含在统计中的字段列表或通配符表达式,以逗号分隔。
ignore_unavailable (bool | None) – 如果为 true,缺失或关闭的索引不包含在响应中。
error_trace (bool | None)
human (bool | None)
pretty (bool | None)
- Return type:
- flush(*, index=None, allow_no_indices=None, error_trace=None, expand_wildcards=None, filter_path=None, force=None, human=None, ignore_unavailable=None, pretty=None, wait_if_ongoing=None)
Flush data streams or indices. Flushing a data stream or index is the process of making sure that any data that is currently only stored in the transaction log is also permanently stored in the Lucene index. When restarting, Elasticsearch replays any unflushed operations from the transaction log into the Lucene index to bring it back into the state that it was in before the restart. Elasticsearch automatically triggers flushes as needed, using heuristics that trade off the size of the unflushed transaction log against the cost of performing each flush.
After each operation has been flushed it is permanently stored in the Lucene index. This may mean that there is no need to maintain an additional copy of it in the transaction log. The transaction log is made up of multiple files, called generations, and Elasticsearch will delete any generation files when they are no longer needed, freeing up disk space.
It is also possible to trigger a flush on one or more indices using the flush API, although it is rare for users to need to call this API directly. If you call the flush API after indexing some documents then a successful response indicates that Elasticsearch has flushed all the documents that were indexed before the flush API was called.
https://www.elastic.co/docs/api/doc/elasticsearch/operation/operation-indices-flush
- Parameters:
index (str | Sequence[str] | None) – Comma-separated list of data streams, indices, and aliases to flush. Supports wildcards (*). To flush all data streams and indices, omit this parameter or use * or _all.
allow_no_indices (bool | None) – If false, the request returns an error if any wildcard expression, index alias, or _all value targets only missing or closed indices. This behavior applies even if the request targets other open indices.
expand_wildcards (Sequence[str | Literal['all', 'closed', 'hidden', 'none', 'open']] | str | ~typing.Literal['all', 'closed', 'hidden', 'none', 'open'] | None) – Type of index that wildcard patterns can match. If the request can target data streams, this argument determines whether wildcard expressions match hidden data streams. Supports comma-separated values, such as open,hidden.
force (bool | None) – If true, the request forces a flush even if there are no changes to commit to the index.
ignore_unavailable (bool | None) – If false, the request returns an error if it targets a missing or closed index.
wait_if_ongoing (bool | None) – If true, the flush operation blocks until execution when another flush operation is running. If false, Elasticsearch returns an error if you request a flush when another flush operation is running.
error_trace (bool | None)
human (bool | None)
pretty (bool | None)
- Return type:
- forcemerge(*, index=None, allow_no_indices=None, error_trace=None, expand_wildcards=None, filter_path=None, flush=None, human=None, ignore_unavailable=None, max_num_segments=None, only_expunge_deletes=None, pretty=None, wait_for_completion=None)
强制执行合并操作。 对一个或多个索引的分片执行强制合并操作。 对于数据流,该API会对该流的所有后备索引分片进行强制合并。
合并通过将部分分片合并在一起,减少每个分片中的段数量,同时释放被删除文档占用的空间。 合并通常会自动进行,但有时手动触发合并很有用。
警告:我们建议仅对只读索引(即不再接收写入的索引)执行强制合并。 当文档被更新或删除时,旧版本不会立即移除,而是被软删除并标记为"墓碑"。 这些软删除文档在常规段合并期间会被自动清理。 但强制合并可能产生非常大的段(超过5GB),这些段不符合常规合并条件。 因此软删除文档数量可能快速增长,导致磁盘使用率升高和搜索性能下降。 如果定期对接收写入的索引强制合并,还会使快照成本更高,因为新文档无法增量备份。
强制合并期间的阻塞
调用此API会阻塞直到合并完成(除非请求包含
wait_for_completion=false)。 如果在完成前客户端连接断开,强制合并过程会在后台继续。 任何对相同索引的新强制合并请求也会阻塞,直到当前合并完成。异步执行强制合并
如果请求包含
wait_for_completion=false,Elasticsearch会执行预检检查,启动请求并返回可用于获取任务状态的任务ID。 但无法取消此任务,因为强制合并任务不可取消。 Elasticsearch会在_tasks/<task_id>创建任务记录文档。 任务完成后应删除该文档以便Elasticsearch回收空间。合并多个索引
通过以下目标可以单次请求强制合并多个索引:
- 包含多个后备索引的一个或多个数据流
- 多个索引
- 一个或多个别名
- 集群中所有数据流和索引
每个目标分片使用force_merge线程池单独合并。 默认每个节点只有一个
force_merge线程,意味着该节点上的分片会逐个合并。 如果扩展节点的force_merge线程池,则可以并行合并分片。强制合并会使被合并分片的存储空间暂时增加,如果
max_num_segments参数设为1,可能需要最多三倍空闲空间将所有段重写为新段。数据流和基于时间的索引
强制合并对管理数据流的旧后备索引和其他基于时间的索引很有用,特别是在滚动更新后。 这些情况下,每个索引只在特定时间段接收写入。 一旦索引不再接收写入,其分片可被强制合并为单个段。 这是个好主意,因为单段分片有时能使用更简单高效的数据结构执行搜索。 例如:
POST /.ds-my-data-stream-2099.03.07-000001/_forcemerge?max_num_segments=1https://www.elastic.co/docs/api/doc/elasticsearch/operation/operation-indices-forcemerge
- Parameters:
index (str | Sequence[str] | None) – 逗号分隔的索引名称列表;使用`_all`或空字符串对所有索引执行操作
allow_no_indices (bool | None) – 是否忽略通配符索引表达式未解析到具体索引的情况(包括`_all`字符串或未指定索引时)
expand_wildcards (Sequence[str | Literal['all', 'closed', 'hidden', 'none', 'open']] | str | ~typing.Literal['all', 'closed', 'hidden', 'none', 'open'] | None) – 是否将通配符表达式展开为打开、关闭或两者兼有的具体索引
flush (bool | None) – 指定操作后是否刷新索引(默认:true)
ignore_unavailable (bool | None) – 当指定索引不可用时(缺失或关闭)是否忽略
max_num_segments (int | None) – 索引应合并成的段数量(默认:动态)
only_expunge_deletes (bool | None) – 指定操作是否仅清除已删除文档
wait_for_completion (bool | None) – 请求是否应等待强制合并完成
error_trace (bool | None)
human (bool | None)
pretty (bool | None)
- Return type:
- get(*, index, allow_no_indices=None, error_trace=None, expand_wildcards=None, features=None, filter_path=None, flat_settings=None, human=None, ignore_unavailable=None, include_defaults=None, local=None, master_timeout=None, pretty=None)
获取索引信息。 获取一个或多个索引的信息。对于数据流,该API返回流的基础索引信息。
https://www.elastic.co/docs/api/doc/elasticsearch/operation/operation-indices-get
- Parameters:
index (str | Sequence[str]) – 用于限制请求的数据流、索引和索引别名的逗号分隔列表 支持通配符表达式(*)。
allow_no_indices (bool | None) – 如果为false,当任何通配符表达式、索引别名或_all值 仅指向缺失或关闭的索引时,请求将返回错误。即使请求同时指向其他打开的索引, 此行为也适用。例如,指向foo*,bar*的请求会在存在以foo开头的索引但不存在 以bar开头的索引时返回错误。
expand_wildcards (Sequence[str | Literal['all', 'closed', 'hidden', 'none', 'open']] | str | ~typing.Literal['all', 'closed', 'hidden', 'none', 'open'] | None) – 通配符表达式可匹配的索引类型。如果请求可以指向数据流, 此参数决定通配符表达式是否匹配隐藏数据流。支持逗号分隔值,如open,hidden。
features (Sequence[str | Literal['aliases', 'mappings', 'settings']] | str | ~typing.Literal['aliases', 'mappings', 'settings'] | None) – 仅返回指定索引特性的信息
flat_settings (bool | None) – 如果为true,以扁平格式返回设置。
ignore_unavailable (bool | None) – 如果为false,指向缺失索引的请求将返回错误。
include_defaults (bool | None) – 如果为true,在响应中返回所有默认设置。
local (bool | None) – 如果为true,请求仅从本地节点获取信息。默认为false,表示从主节点 获取信息。
master_timeout (str | Literal[-1] | ~typing.Literal[0] | None) – 等待连接主节点的超时时间。如果在超时前未收到响应, 请求将失败并返回错误。
error_trace (bool | None)
human (bool | None)
pretty (bool | None)
- Return type:
- get_alias(*, index=None, name=None, allow_no_indices=None, error_trace=None, expand_wildcards=None, filter_path=None, human=None, ignore_unavailable=None, master_timeout=None, pretty=None)
获取别名。 检索一个或多个数据流或索引别名的信息。
https://www.elastic.co/docs/api/doc/elasticsearch/operation/operation-indices-get-alias
- Parameters:
index (str | Sequence[str] | None) – 用于限制请求的数据流或索引的逗号分隔列表。支持通配符(*)。若要针对所有数据流和索引,请省略此参数或使用`*`或`_all`。
name (str | Sequence[str] | None) – 要检索的别名的逗号分隔列表。支持通配符(*)。若要检索所有别名,请省略此参数或使用`*`或`_all`。
allow_no_indices (bool | None) – 如果为`false`,当任何通配符表达式、索引别名或`_all`值仅指向缺失或关闭的索引时,请求将返回错误。即使请求同时针对其他打开的索引,此行为也适用。
expand_wildcards (Sequence[str | Literal['all', 'closed', 'hidden', 'none', 'open']] | str | ~typing.Literal['all', 'closed', 'hidden', 'none', 'open'] | None) – 通配符模式可匹配的索引类型。如果请求可以针对数据流,此参数决定通配符表达式是否匹配隐藏的数据流。支持逗号分隔的值,例如`open,hidden`。
ignore_unavailable (bool | None) – 如果为`false`,当请求指向缺失或关闭的索引时将返回错误。
master_timeout (str | Literal[-1] | ~typing.Literal[0] | None) – 等待连接到主节点的时间段。如果在超时到期前未收到响应,则请求失败并返回错误。
error_trace (bool | None)
human (bool | None)
pretty (bool | None)
- Return type:
- get_data_lifecycle(*, name, error_trace=None, expand_wildcards=None, filter_path=None, human=None, include_defaults=None, master_timeout=None, pretty=None)
获取数据流的生命周期。
获取一个或多个数据流的生命周期配置。
https://www.elastic.co/docs/api/doc/elasticsearch/operation/operation-indices-get-data-lifecycle
- Parameters:
name (str | Sequence[str]) – 逗号分隔的数据流列表,用于限制请求范围。支持通配符(*)。若要针对所有数据流,可省略此参数或使用`*`或`_all`。
expand_wildcards (Sequence[str | Literal['all', 'closed', 'hidden', 'none', 'open']] | str | ~typing.Literal['all', 'closed', 'hidden', 'none', 'open'] | None) – 通配符可匹配的数据流类型。支持逗号分隔的值,例如`open,hidden`。
include_defaults (bool | None) – 若为`true`,则在响应中返回所有默认设置。
master_timeout (str | Literal[-1] | ~typing.Literal[0] | None) – 等待连接主节点的超时时间。如果在超时前未收到响应,则请求失败并返回错误。
error_trace (bool | None)
human (bool | None)
pretty (bool | None)
- Return type:
- get_data_lifecycle_stats(*, error_trace=None, filter_path=None, human=None, pretty=None)
获取数据流生命周期统计信息。
获取由数据流生命周期管理的数据流相关统计信息。
- get_data_stream(*, name=None, error_trace=None, expand_wildcards=None, filter_path=None, human=None, include_defaults=None, master_timeout=None, pretty=None, verbose=None)
获取数据流。
获取一个或多个数据流的相关信息。
https://www.elastic.co/docs/api/doc/elasticsearch/operation/operation-indices-get-data-stream
- Parameters:
name (str | Sequence[str] | None) – 用于限制请求的数据流名称逗号分隔列表。 支持通配符(*)表达式。如果省略,则返回所有数据流。
expand_wildcards (Sequence[str | Literal['all', 'closed', 'hidden', 'none', 'open']] | str | ~typing.Literal['all', 'closed', 'hidden', 'none', 'open'] | None) – 通配符可匹配的数据流类型。 支持逗号分隔值,如`open,hidden`。
include_defaults (bool | None) – 如果为true,则返回索引模板的所有相关默认配置。
master_timeout (str | Literal[-1] | ~typing.Literal[0] | None) – 等待连接主节点的时间。如果 在超时前未收到响应,则请求失败并返回错误。
verbose (bool | None) – 是否应计算并返回每个数据流的最大时间戳。
error_trace (bool | None)
human (bool | None)
pretty (bool | None)
- Return type:
- get_data_stream_mappings(*, name, error_trace=None, filter_path=None, human=None, master_timeout=None, pretty=None)
获取数据流映射。
获取一个或多个数据流的映射信息。
- Parameters:
- Return type:
- get_data_stream_options(*, name, error_trace=None, expand_wildcards=None, filter_path=None, human=None, master_timeout=None, pretty=None)
获取数据流选项。
获取一个或多个数据流的数据流选项配置。
https://www.elastic.co/guide/en/elasticsearch/reference/master/index.html
- Parameters:
name (str | Sequence[str]) – 限制请求的数据流逗号分隔列表。支持 通配符(*)。要针对所有数据流,请省略此参数或使用`*` 或`_all`。
expand_wildcards (Sequence[str | Literal['all', 'closed', 'hidden', 'none', 'open']] | str | ~typing.Literal['all', 'closed', 'hidden', 'none', 'open'] | None) – 通配符可匹配的数据流类型。 支持逗号分隔值,如`open,hidden`。
master_timeout (str | Literal[-1] | ~typing.Literal[0] | None) – 等待连接主节点的时间。如果 在超时前未收到响应,则请求失败并返回错误。
error_trace (bool | None)
human (bool | None)
pretty (bool | None)
- Return type:
- get_data_stream_settings(*, name, error_trace=None, filter_path=None, human=None, master_timeout=None, pretty=None)
获取数据流设置。
获取一个或多个数据流的设置信息。
- Parameters:
- Return type:
- get_field_mapping(*, fields, index=None, allow_no_indices=None, error_trace=None, expand_wildcards=None, filter_path=None, human=None, ignore_unavailable=None, include_defaults=None, pretty=None)
获取映射定义。 检索一个或多个字段的映射定义。 对于数据流,API 会检索该流后备索引的字段映射。
如果您不需要完整的映射,或者索引映射包含大量字段,此 API 非常有用。
https://www.elastic.co/docs/api/doc/elasticsearch/operation/operation-indices-get-mapping
- Parameters:
fields (str | Sequence[str]) – 用于限制返回信息的字段逗号分隔列表或通配符表达式。支持通配符 (*)。
index (str | Sequence[str] | None) – 用于限制请求的数据流、索引和别名的逗号分隔列表。支持通配符 (*)。要针对所有数据流和索引,请省略此参数或使用 * 或 _all。
allow_no_indices (bool | None) – 如果为 false,当任何通配符表达式、索引别名或 _all 值仅指向缺失或关闭的索引时,请求将返回错误。即使请求针对其他打开的索引,此行为也适用。
expand_wildcards (Sequence[str | Literal['all', 'closed', 'hidden', 'none', 'open']] | str | ~typing.Literal['all', 'closed', 'hidden', 'none', 'open'] | None) – 通配符模式可以匹配的索引类型。如果请求可以针对数据流,此参数决定通配符表达式是否匹配隐藏的数据流。支持逗号分隔的值,例如 open,hidden。
ignore_unavailable (bool | None) – 如果为 false,当请求针对缺失或关闭的索引时将返回错误。
include_defaults (bool | None) – 如果为 true,在响应中返回所有默认设置。
error_trace (bool | None)
human (bool | None)
pretty (bool | None)
- Return type:
- get_index_template(*, name=None, error_trace=None, filter_path=None, flat_settings=None, human=None, include_defaults=None, local=None, master_timeout=None, pretty=None)
获取索引模板。 获取一个或多个索引模板的信息。
https://www.elastic.co/docs/api/doc/elasticsearch/operation/operation-indices-get-index-template
- Parameters:
name (str | None) – 用于限制请求的索引模板名称的逗号分隔列表。支持通配符 (*) 表达式。
flat_settings (bool | None) – 如果为 true,以扁平格式返回设置。
include_defaults (bool | None) – 如果为 true,返回索引模板的所有相关默认配置。
local (bool | None) – 如果为 true,请求仅从本地节点检索信息。默认为 false,表示从主节点检索信息。
master_timeout (str | Literal[-1] | ~typing.Literal[0] | None) – 等待连接到主节点的超时时间。如果在超时到期前未收到响应,则请求失败并返回错误。
error_trace (bool | None)
human (bool | None)
pretty (bool | None)
- Return type:
- get_mapping(*, index=None, allow_no_indices=None, error_trace=None, expand_wildcards=None, filter_path=None, human=None, ignore_unavailable=None, local=None, master_timeout=None, pretty=None)
获取映射定义。 对于数据流,API 会检索该流后备索引的映射。
https://www.elastic.co/docs/api/doc/elasticsearch/operation/operation-indices-get-mapping
- Parameters:
index (str | Sequence[str] | None) – 用于限制请求的数据流、索引和别名的逗号分隔列表。支持通配符 (*)。要针对所有数据流和索引,请省略此参数或使用 * 或 _all。
allow_no_indices (bool | None) – 如果为 false,当任何通配符表达式、索引别名或 _all 值仅指向缺失或关闭的索引时,请求将返回错误。即使请求针对其他打开的索引,此行为也适用。
expand_wildcards (Sequence[str | Literal['all', 'closed', 'hidden', 'none', 'open']] | str | ~typing.Literal['all', 'closed', 'hidden', 'none', 'open'] | None) – 通配符模式可以匹配的索引类型。如果请求可以针对数据流,此参数决定通配符表达式是否匹配隐藏的数据流。支持逗号分隔的值,例如 open,hidden。
ignore_unavailable (bool | None) – 如果为 false,当请求针对缺失或关闭的索引时将返回错误。
local (bool | None) – 如果为 true,请求仅从本地节点检索信息。
master_timeout (str | Literal[-1] | ~typing.Literal[0] | None) – 等待连接到主节点的超时时间。如果在超时到期前未收到响应,则请求失败并返回错误。
error_trace (bool | None)
human (bool | None)
pretty (bool | None)
- Return type:
- get_migrate_reindex_status(*, index, error_trace=None, filter_path=None, human=None, pretty=None)
获取迁移重新索引状态。
获取数据流或索引的迁移重新索引尝试的状态。
https://www.elastic.co/docs/api/doc/elasticsearch/group/endpoint-migration
- get_settings(*, index=None, name=None, allow_no_indices=None, error_trace=None, expand_wildcards=None, filter_path=None, flat_settings=None, human=None, ignore_unavailable=None, include_defaults=None, local=None, master_timeout=None, pretty=None)
获取索引设置。 获取一个或多个索引的设置信息。 对于数据流,它返回该流后备索引的设置信息。
https://www.elastic.co/docs/api/doc/elasticsearch/operation/operation-indices-get-settings
- Parameters:
index (str | Sequence[str] | None) – 用于限制请求的数据流、索引和别名的逗号分隔列表。支持通配符 (*)。要针对所有数据流和索引,请省略此参数或使用 * 或 _all。
allow_no_indices (bool | None) – 如果为 false,当任何通配符表达式、索引别名或 _all 值仅指向缺失或关闭的索引时,请求将返回错误。即使请求针对其他打开的索引,此行为也适用。例如,针对 foo*,bar* 的请求如果存在以 foo 开头的索引但没有以 bar 开头的索引,将返回错误。
expand_wildcards (Sequence[str | Literal['all', 'closed', 'hidden', 'none', 'open']] | str | ~typing.Literal['all', 'closed', 'hidden', 'none', 'open'] | None) – 通配符模式可以匹配的索引类型。如果请求可以针对数据流,此参数决定通配符表达式是否匹配隐藏的数据流。支持逗号分隔的值,例如 open,hidden。
flat_settings (bool | None) – 如果为 true,以扁平格式返回设置。
ignore_unavailable (bool | None) – 如果为 false,当请求针对缺失或关闭的索引时将返回错误。
include_defaults (bool | None) – 如果为 true,在响应中返回所有默认设置。
local (bool | None) – 如果为 true,请求仅从本地节点检索信息。如果为 false,则从主节点检索信息。
master_timeout (str | Literal[-1] | ~typing.Literal[0] | None) – 等待连接到主节点的超时时间。如果在超时到期前未收到响应,则请求失败并返回错误。
error_trace (bool | None)
human (bool | None)
pretty (bool | None)
- Return type:
- get_template(*, name=None, error_trace=None, filter_path=None, flat_settings=None, human=None, local=None, master_timeout=None, pretty=None)
获取旧版索引模板。 获取一个或多个索引模板的信息。
重要说明:本文档涉及已弃用的旧版索引模板,它们将被 Elasticsearch 7.8 引入的可组合模板取代。
https://www.elastic.co/docs/api/doc/elasticsearch/operation/operation-indices-get-template
- Parameters:
name (str | Sequence[str] | None) – 用于限制请求的索引模板名称的逗号分隔列表。 支持通配符(*)表达式。若要返回所有索引模板, 请省略此参数或使用`_all`或`*`值。
flat_settings (bool | None) – 如果为`true`,则以扁平格式返回设置。
local (bool | None) – 如果为`true`,请求仅从本地节点检索信息。
master_timeout (str | Literal[-1] | ~typing.Literal[0] | None) – 等待连接主节点的时间段。如果 在超时到期前未收到响应,则请求失败并返回错误。
error_trace (bool | None)
human (bool | None)
pretty (bool | None)
- Return type:
- migrate_reindex(*, reindex=None, body=None, error_trace=None, filter_path=None, human=None, pretty=None)
重新索引旧版后备索引。
为数据流重新索引所有旧版后备索引。 此操作在持久任务中执行。 持久任务ID会立即返回,重新索引工作在该任务中完成。
https://www.elastic.co/docs/api/doc/elasticsearch/operation/operation-indices-migrate-reindex
- migrate_to_data_stream(*, name, error_trace=None, filter_path=None, human=None, master_timeout=None, pretty=None, timeout=None)
将索引别名转换为数据流。 将索引别名转换为数据流。 您必须有一个匹配的已启用数据流的索引模板。 别名必须满足以下条件: 别名必须有一个写入索引; 别名的所有索引必须具有`@timestamp`字段映射为`date`或`date_nanos`字段类型; 别名不能有任何过滤器; 别名不能使用自定义路由。 如果成功,请求将移除别名并创建同名数据流。 别名的索引将成为流的隐藏后备索引。 别名的写入索引将成为流的写入索引。
https://www.elastic.co/docs/api/doc/elasticsearch/operation/operation-indices-migrate-to-data-stream
- Parameters:
- Return type:
- modify_data_stream(*, actions=None, error_trace=None, filter_path=None, human=None, pretty=None, body=None)
更新数据流。 在单个原子操作中执行一个或多个数据流修改操作。
https://www.elastic.co/docs/api/doc/elasticsearch/operation/operation-indices-modify-data-stream
- open(*, index, allow_no_indices=None, error_trace=None, expand_wildcards=None, filter_path=None, human=None, ignore_unavailable=None, master_timeout=None, pretty=None, timeout=None, wait_for_active_shards=None)
打开已关闭的索引。 对于数据流,API会打开任何已关闭的后备索引。
已关闭的索引会阻止读/写操作,并且不允许开放索引允许的所有操作。 无法在已关闭的索引中索引文档或搜索文档。 这使得已关闭的索引不必维护用于索引或搜索文档的内部数据结构,从而减少集群的开销。
当打开或关闭索引时,主节点负责重新启动索引分片以反映索引的新状态。 然后分片将经历正常的恢复过程。 集群会自动复制已打开或关闭索引的数据,以确保始终安全地保留足够的分片副本。
您可以打开和关闭多个索引。 如果请求显式引用缺失的索引,则会抛出错误。 可以通过使用`ignore_unavailable=true`参数关闭此行为。
默认情况下,您必须显式命名要打开或关闭的索引。 要使用`_all`、`*`或其他通配符表达式打开或关闭索引,请将`action.destructive_requires_name`设置更改为`false`。 也可以通过集群更新设置API更改此设置。
已关闭的索引会消耗大量磁盘空间,这可能导致托管环境中的问题。 可以通过集群设置API将`cluster.indices.close.enable`设置为`false`来关闭索引功能。
因为打开或关闭索引会分配其分片,所以索引创建时的`wait_for_active_shards`设置也适用于`_open`和`_close`索引操作。
https://www.elastic.co/docs/api/doc/elasticsearch/operation/operation-indices-open
- Parameters:
index (str | Sequence[str]) – 用于限制请求的数据流、索引和别名的逗号分隔列表。 支持通配符(*)。默认情况下,您必须显式 命名用于限制请求的索引。要使用`_all`、*`或其他通配符表达式限制请求, 请将`action.destructive_requires_name`设置为false。您可以在`elasticsearch.yml 文件中或使用集群更新设置API更新此设置。
allow_no_indices (bool | None) – 如果为`false`,当任何通配符表达式、索引别名或`_all`值仅针对缺失或关闭的索引时,请求返回错误。 即使请求针对其他开放索引,此行为也适用。
expand_wildcards (Sequence[str | Literal['all', 'closed', 'hidden', 'none', 'open']] | str | ~typing.Literal['all', 'closed', 'hidden', 'none', 'open'] | None) – 通配符模式可以匹配的索引类型。如果 请求可以针对数据流,此参数确定通配符表达式是否匹配隐藏数据流。支持逗号分隔值, 例如`open,hidden`。
ignore_unavailable (bool | None) – 如果为`false`,当请求针对缺失或关闭的索引时返回错误。
master_timeout (str | Literal[-1] | ~typing.Literal[0] | None) – 等待连接主节点的时间段。如果 在超时到期前未收到响应,则请求失败并返回错误。
timeout (str | Literal[-1] | ~typing.Literal[0] | None) – 等待响应的时间段。如果在超时到期前 未收到响应,则请求失败并返回错误。
wait_for_active_shards (int | str | Literal['all', 'index-setting'] | None) – 操作前必须激活的分片副本数。 设置为`all`或任何正整数,最大为索引中的总分片数(number_of_replicas+1)。
error_trace (bool | None)
human (bool | None)
pretty (bool | None)
- Return type:
- promote_data_stream(*, name, error_trace=None, filter_path=None, human=None, master_timeout=None, pretty=None)
提升数据流。 将由跨集群复制(CCR)管理的复制数据流提升为常规数据流。
通过CCR自动跟随功能,远程集群的数据流可以被复制到本地集群。 这些数据流在本地集群中无法执行滚动更新操作。 只有当上游数据流滚动更新时,这些复制的数据流才会随之滚动更新。 当远程集群不可用时,可以将本地集群中的数据流提升为常规数据流,从而允许在本地集群中执行滚动更新操作。
注意:提升数据流时,请确保本地集群有一个匹配该数据流的启用数据流索引模板。 如果缺少此模板,数据流将无法滚动更新,直到创建匹配的索引模板为止。 这会影响数据流的生命周期管理,干扰数据流的大小和保留策略。
https://www.elastic.co/docs/api/doc/elasticsearch/operation/operation-indices-promote-data-stream
- put_alias(*, index, name, error_trace=None, filter=None, filter_path=None, human=None, index_routing=None, is_write_index=None, master_timeout=None, pretty=None, routing=None, search_routing=None, timeout=None, body=None)
创建或更新别名。 将数据流或索引添加到别名中。
https://www.elastic.co/docs/api/doc/elasticsearch/operation/operation-indices-put-alias
- Parameters:
index (str | Sequence[str]) – 要添加的数据流或索引的逗号分隔列表。支持 通配符(*)。匹配数据流和索引的通配符模式会返回错误。
name (str) – 要更新的别名。如果别名不存在,请求将创建 它。索引别名名称支持日期计算。
index_routing (str | None) – 用于将索引操作路由到特定分片的值。 如果指定,将覆盖索引操作的`routing`值。 数据流别名不支持此参数。
is_write_index (bool | None) – 如果为`true`,设置该别名的写入索引或数据流。如果别名指向 多个索引或数据流且未设置`is_write_index`, 别名将拒绝写入请求。如果索引别名指向 一个索引且未设置`is_write_index`,该索引自动作为 写入索引。数据流别名不会自动设置写入数据流, 即使别名指向一个数据流。
master_timeout (str | Literal[-1] | ~typing.Literal[0] | None) – 等待连接主节点的超时时间。如果 在超时前未收到响应,请求将失败并返回错误。
routing (str | None) – 用于将索引和搜索操作路由到特定分片的值。 数据流别名不支持此参数。
search_routing (str | None) – 用于将搜索操作路由到特定分片的值。 如果指定,将覆盖搜索操作的`routing`值。 数据流别名不支持此参数。
timeout (str | Literal[-1] | ~typing.Literal[0] | None) – 等待响应的超时时间。如果在超时前 未收到响应,请求将失败并返回错误。
error_trace (bool | None)
human (bool | None)
pretty (bool | None)
- Return type:
- put_data_lifecycle(*, name, data_retention=None, downsampling=None, enabled=None, error_trace=None, expand_wildcards=None, filter_path=None, human=None, master_timeout=None, pretty=None, timeout=None, body=None)
更新数据流生命周期。 更新指定数据流的数据流生命周期配置。
https://www.elastic.co/docs/api/doc/elasticsearch/operation/operation-indices-put-data-lifecycle
- Parameters:
name (str | Sequence[str]) – 用于限制请求的数据流逗号分隔列表。 支持通配符(*)。要针对所有数据流,请使用`*`或`_all`。
data_retention (str | Literal[-1] | ~typing.Literal[0] | None) – 如果定义,添加到该数据流的每个文档将 至少存储这段时间。超过此持续时间后,文档可能被删除。 如果为空,该数据流中的文档将无限期存储。
downsampling (Mapping[str, Any] | None) – 滚动更新后为托管后备索引执行的 降采样配置。
enabled (bool | None) – 如果定义,将为此数据流开启/关闭(true/false) 数据流生命周期。禁用(enabled: false)的数据流生命周期 不会对数据流产生任何影响。
expand_wildcards (Sequence[str | Literal['all', 'closed', 'hidden', 'none', 'open']] | str | ~typing.Literal['all', 'closed', 'hidden', 'none', 'open'] | None) – 通配符可以匹配的数据流类型。 支持逗号分隔值,如`open,hidden`。
master_timeout (str | Literal[-1] | ~typing.Literal[0] | None) – 等待连接主节点的超时时间。如果 在超时前未收到响应,请求将失败并返回错误。
timeout (str | Literal[-1] | ~typing.Literal[0] | None) – 等待响应的超时时间。如果在超时前 未收到响应,请求将失败并返回错误。
error_trace (bool | None)
human (bool | None)
pretty (bool | None)
- Return type:
- put_data_stream_mappings(*, name, mappings=None, body=None, dry_run=None, error_trace=None, filter_path=None, human=None, master_timeout=None, pretty=None, timeout=None)
更新数据流映射。
此API可用于覆盖特定数据流的映射配置。这些覆盖将优先于 数据流匹配模板中的配置。映射变更仅适用于调用此API后 滚动更新创建的新写入索引。此API不会更改任何现有索引。
- Parameters:
dry_run (bool | None) – 如果为`true`,请求实际上不会更改任何数据流的映射 配置。而是模拟更改设置,并向用户报告如果实际应用 这些设置会发生什么。
master_timeout (str | Literal[-1] | ~typing.Literal[0] | None) – 等待连接主节点的超时时间。 如果在超时前未收到响应,请求将失败 并返回错误。
timeout (str | Literal[-1] | ~typing.Literal[0] | None) – 等待响应的超时时间。如果在超时前未收到 响应,请求将失败并返回错误。
error_trace (bool | None)
human (bool | None)
pretty (bool | None)
- Return type:
- put_data_stream_options(*, name, error_trace=None, expand_wildcards=None, failure_store=None, filter_path=None, human=None, master_timeout=None, pretty=None, timeout=None, body=None)
更新数据流选项。 更新指定数据流的数据流选项配置。
https://www.elastic.co/guide/en/elasticsearch/reference/master/index.html
- Parameters:
name (str | Sequence[str]) – 用于限制请求的数据流逗号分隔列表。 支持通配符(*)。要针对所有数据流,请使用`*`或`_all`。
expand_wildcards (Sequence[str | Literal['all', 'closed', 'hidden', 'none', 'open']] | str | ~typing.Literal['all', 'closed', 'hidden', 'none', 'open'] | None) – 通配符可以匹配的数据流类型。 支持逗号分隔值,如`open,hidden`。
failure_store (Mapping[str, Any] | None) – 如果定义,将更新由名称表达式解析的每个数据流的 故障存储配置。
master_timeout (str | Literal[-1] | ~typing.Literal[0] | None) – 等待连接主节点的超时时间。如果 在超时前未收到响应,请求将失败并返回错误。
timeout (str | Literal[-1] | ~typing.Literal[0] | None) – 等待响应的超时时间。如果在超时前 未收到响应,请求将失败并返回错误。
error_trace (bool | None)
human (bool | None)
pretty (bool | None)
- Return type:
- put_data_stream_settings(*, name, settings=None, body=None, dry_run=None, error_trace=None, filter_path=None, human=None, master_timeout=None, pretty=None, timeout=None)
更新数据流设置。
此API可用于覆盖特定数据流的设置。这些覆盖设置将优先于数据流匹配模板中的指定内容。为防止数据流进入无效状态, 仅允许修改特定设置。如果可能,设置变更将应用于所有后备索引。否则,将在数据流下次滚动更新时应用。
- Parameters:
dry_run (bool | None) – 若为`true`,请求不会实际更改任何数据流或索引的设置,而是模拟设置变更并返回如果应用这些设置将会发生的结果
master_timeout (str | Literal[-1] | ~typing.Literal[0] | None) – 等待连接主节点的超时时间。如果在超时前未收到响应,请求将失败并返回错误
timeout (str | Literal[-1] | ~typing.Literal[0] | None) – 等待响应的超时时间。如果在超时前未收到响应,请求将失败并返回错误
error_trace (bool | None)
human (bool | None)
pretty (bool | None)
- Return type:
- put_index_template(*, name, allow_auto_create=None, cause=None, composed_of=None, create=None, data_stream=None, deprecated=None, error_trace=None, filter_path=None, human=None, ignore_missing_component_templates=None, index_patterns=None, master_timeout=None, meta=None, pretty=None, priority=None, template=None, version=None, body=None)
创建或更新索引模板。 索引模板定义了可自动应用于新索引的设置、映射和别名。
Elasticsearch根据匹配索引名称的通配符模式将模板应用于新索引。 索引模板在数据流或索引创建期间应用。 对于数据流,这些设置和映射会在流的后备索引创建时应用。 创建索引API请求中指定的设置和映射会覆盖索引模板中的任何设置或映射。 对索引模板的更改不会影响现有索引,包括数据流的现有后备索引。
您可以在索引模板中使用C风格的
/* *\/块注释。 可以在请求体中的任何位置包含注释,除了左大括号之前。多重匹配模板
如果多个索引模板匹配新索引或数据流的名称,将使用优先级最高的模板。
不允许存在相同优先级且索引模式重叠的多个模板,当尝试创建与现有索引模板在相同优先级下匹配的模板时会抛出错误。
组合别名、映射和设置
当在索引模板的
composed_of字段中指定多个组件模板时,它们按指定顺序合并,意味着后面的组件模板会覆盖前面的组件模板。 接着合并来自父索引模板的任何映射、设置或别名。 最后合并索引请求本身的任何配置。 映射定义是递归合并的,这意味着后面的映射组件可以引入新的字段映射并更新映射配置。 如果字段映射已包含在前面的组件中,其定义将被后面的组件完全覆盖。 这种递归合并策略不仅适用于字段映射,也适用于根选项如dynamic_templates和meta。 如果前面的组件包含dynamic_templates块,默认情况下新的dynamic_templates条目会追加到末尾。 如果已存在相同键的条目,则会被新定义覆盖。https://www.elastic.co/docs/api/doc/elasticsearch/operation/operation-indices-put-index-template
- Parameters:
name (str) – 索引或模板名称
allow_auto_create (bool | None) – 此设置覆盖集群设置`action.auto_create_index`的值。 如果在模板中设置为`true`,即使通过`actions.auto_create_index`禁用索引自动创建, 也可以使用该模板自动创建索引。如果设置为`false`,则必须显式创建匹配该模板的索引或数据流, 且永远不会自动创建。
cause (str | None) – 用户定义的创建/更新索引模板原因
composed_of (Sequence[str] | None) – 组件模板名称的有序列表。组件模板按指定顺序合并, 意味着最后指定的组件模板具有最高优先级。
create (bool | None) – 若为`true`,此请求不能替换或更新现有索引模板
data_stream (Mapping[str, Any] | None) – 如果包含此对象,模板将用于创建数据流及其后备索引。支持空对象。 数据流需要具有`data_stream`对象的匹配索引模板。
deprecated (bool | None) – 将此索引模板标记为已弃用。当创建或更新使用已弃用组件的非弃用索引模板时, Elasticsearch将发出弃用警告。
ignore_missing_component_templates (Sequence[str] | None) – 当索引模板引用的组件模板可能不存在时, 可以使用配置选项ignore_missing_component_templates
master_timeout (str | Literal[-1] | ~typing.Literal[0] | None) – 等待连接主节点的超时时间。如果在超时前未收到响应,请求将失败并返回错误
meta (Mapping[str, Any] | None) – 关于索引模板的可选用户元数据。可以包含任何内容。 这些用户定义的对象存储在集群状态中,因此最好保持简短。要取消设置元数据,替换模板时不指定它。
priority (int | None) – 确定创建新数据流或索引时索引模板优先级的数值。选择优先级最高的索引模板。 如果未指定优先级,则模板被视为优先级0(最低优先级)。此数值不是由Elasticsearch自动生成的。
template (Mapping[str, Any] | None) – 要应用的模板。可选包含`aliases`、`mappings`或`settings`配置
version (int | None) – 用于外部管理索引模板的版本号。此数值不是由Elasticsearch自动生成的。 外部系统可以使用这些版本号简化模板管理。要取消设置版本,替换模板时不指定版本号。
error_trace (bool | None)
human (bool | None)
pretty (bool | None)
- Return type:
- put_mapping(*, index, allow_no_indices=None, date_detection=None, dynamic=None, dynamic_date_formats=None, dynamic_templates=None, error_trace=None, expand_wildcards=None, field_names=None, filter_path=None, human=None, ignore_unavailable=None, master_timeout=None, meta=None, numeric_detection=None, pretty=None, properties=None, routing=None, runtime=None, source=None, timeout=None, write_index_only=None, body=None)
更新字段映射。 向现有数据流或索引添加新字段。 您可以使用更新映射API来:
- 向现有索引添加新字段
- 在单个请求中更新多个索引的映射
- 向对象字段添加新属性
- 为现有字段启用多字段
- 更新支持的映射参数
- 通过重新索引更改字段映射
- 使用字段别名重命名字段
在更新映射API示例指南中了解如何使用更新映射API的实际示例。
https://www.elastic.co/docs/api/doc/elasticsearch/operation/operation-indices-put-mapping
- Parameters:
index (str | Sequence[str]) – 逗号分隔的应添加映射的索引名称列表(支持通配符);使用`_all`或省略可在所有索引上添加映射
allow_no_indices (bool | None) – 若为`false`,当任何通配符表达式、索引别名或`_all`值仅指向缺失或关闭的索引时,请求返回错误。 即使请求目标指向其他打开的索引,此行为也适用
date_detection (bool | None) – 控制是否启用动态日期检测
dynamic (str | Literal['false', 'runtime', 'strict', 'true'] | None) – 控制是否动态添加新字段
dynamic_date_formats (Sequence[str] | None) – 如果启用日期检测,则新字符串字段会与’dynamic_date_formats’进行匹配检查, 如果值匹配则会添加新的日期字段而非字符串
dynamic_templates (Sequence[Mapping[str, Mapping[str, Any]]] | None) – 为映射指定动态模板
expand_wildcards (Sequence[str | Literal['all', 'closed', 'hidden', 'none', 'open']] | str | ~typing.Literal['all', 'closed', 'hidden', 'none', 'open'] | None) – 通配符模式可匹配的索引类型。如果请求可以针对数据流,此参数决定通配符表达式是否匹配隐藏数据流。 支持逗号分隔值,如`open,hidden`
ignore_unavailable (bool | None) – 若为`false`,当请求目标指向缺失或关闭的索引时返回错误
master_timeout (str | Literal[-1] | ~typing.Literal[0] | None) – 等待连接主节点的超时时间。如果在超时前未收到响应,请求将失败并返回错误
meta (Mapping[str, Any] | None) – 映射类型可以关联自定义元数据。Elasticsearch完全不使用这些元数据,但可用于存储应用程序特定的元数据
numeric_detection (bool | None) – 为所有字段自动将字符串映射为数值数据类型
properties (Mapping[str, Mapping[str, Any]] | None) – 字段的映射。对于新字段,此映射可包含: - 字段名称 - 字段数据类型 - 映射参数
runtime (Mapping[str, Mapping[str, Any]] | None) – 索引的运行时字段映射
timeout (str | Literal[-1] | ~typing.Literal[0] | None) – 等待响应的超时时间。如果在超时前未收到响应,请求将失败并返回错误
write_index_only (bool | None) – 若为`true`,映射仅应用于目标的当前写入索引
error_trace (bool | None)
human (bool | None)
pretty (bool | None)
- Return type:
- put_settings(*, settings=None, body=None, index=None, allow_no_indices=None, error_trace=None, expand_wildcards=None, filter_path=None, flat_settings=None, human=None, ignore_unavailable=None, master_timeout=None, preserve_existing=None, pretty=None, reopen=None, timeout=None)
更新索引设置。 实时更改动态索引设置。 对于数据流,默认情况下索引设置更改会应用于所有后备索引。
要将设置恢复为默认值,请使用null值。 可以在索引设置文档中找到可在实时索引上动态更新的每索引设置列表。 要防止现有设置被更新,将
preserve_existing参数设置为true。为了在批量索引期间优化性能,可以禁用刷新间隔。 参考禁用刷新间隔获取示例。 在请求体中有多种有效方式表示索引设置。您可以仅指定设置,例如:
{ "number_of_replicas": 1 }或者可以使用
index设置对象:{ "index": { "number_of_replicas": 1 } }或者使用点注释:
{ "index.number_of_replicas": 1 }或者可以将上述任何选项嵌入
settings对象中。例如:{ "settings": { "index": { "number_of_replicas": 1 } } }注意:只能在关闭的索引上定义新分析器。 要添加分析器,必须关闭索引、定义分析器然后重新打开索引。 不能关闭数据流的写入索引。 要更新数据流写入索引和未来后备索引的分析器,请更新流使用的索引模板中的分析器。 然后滚动更新数据流以将新分析器应用于流的写入索引和未来后备索引。 这会影响搜索和滚动更新后添加到流的任何新数据。 但是,它不会影响数据流的后备索引或其现有数据。 要更改现有后备索引的分析器,必须创建新的数据流并将数据重新索引到其中。 参考在现有索引上更新分析器获取分步示例。
https://www.elastic.co/docs/api/doc/elasticsearch/operation/operation-indices-put-settings
- Parameters:
index (str | Sequence[str] | None) – 逗号分隔的数据流、索引和别名列表,用于限制请求范围。支持通配符(*)。 要针对所有数据流和索引,请省略此参数或使用`*`或`_all`
allow_no_indices (bool | None) – 若为`false`,当任何通配符表达式、索引别名或`_all`值仅指向缺失或关闭的索引时,请求返回错误。 即使请求目标指向其他打开的索引,此行为也适用。例如,针对`foo*,bar*`的请求如果存在以`foo`开头的索引但没有以`bar`开头的索引,则会返回错误
expand_wildcards (Sequence[str | Literal['all', 'closed', 'hidden', 'none', 'open']] | str | ~typing.Literal['all', 'closed', 'hidden', 'none', 'open'] | None) – 通配符模式可匹配的索引类型。如果请求可以针对数据流,此参数决定通配符表达式是否匹配隐藏数据流。 支持逗号分隔值,如`open,hidden`
flat_settings (bool | None) – 若为`true`,以扁平格式返回设置
ignore_unavailable (bool | None) – 若为`true`,以扁平格式返回设置
master_timeout (str | Literal[-1] | ~typing.Literal[0] | None) – 等待连接主节点的超时时间。如果在超时前未收到响应,请求将失败并返回错误
preserve_existing (bool | None) – 若为`true`,现有索引设置保持不变
reopen (bool | None) – 是否关闭并重新打开索引以应用非动态设置。 如果设置为`true`,应用设置的索引将暂时关闭然后重新打开以应用更改
timeout (str | Literal[-1] | ~typing.Literal[0] | None) – 等待响应的超时时间。如果在超时前未收到响应,请求将失败并返回错误
error_trace (bool | None)
human (bool | None)
pretty (bool | None)
- Return type:
- put_template(*, name, aliases=None, cause=None, create=None, error_trace=None, filter_path=None, human=None, index_patterns=None, mappings=None, master_timeout=None, order=None, pretty=None, settings=None, version=None, body=None)
创建或更新传统索引模板。 索引模板定义了可自动应用于新索引的设置、映射和别名。 Elasticsearch根据匹配索引名称的索引模式将模板应用于新索引。
重要说明:此文档是关于传统索引模板的,这些模板已被弃用,将被Elasticsearch 7.8中引入的可组合模板取代。
可组合模板始终优先于传统模板。 如果没有可组合模板匹配新索引,则按顺序应用匹配的传统模板。
索引模板仅在索引创建期间应用。 对索引模板的更改不会影响现有索引。 创建索引API请求中指定的设置和映射会覆盖索引模板中的任何设置或映射。
您可以在索引模板中使用C风格的
/* *\/块注释。 可以在请求体中的任何位置包含注释,除了左大括号之前。匹配多个模板的索引
多个索引模板可能匹配一个索引,在这种情况下,设置和映射都将合并到索引的最终配置中。 可以使用order参数控制合并顺序,较低order值先应用,较高order值覆盖它们。 注意:具有相同order值的多个匹配模板将导致非确定性的合并顺序。
https://www.elastic.co/docs/api/doc/elasticsearch/operation/operation-indices-put-template
- Parameters:
name (str) – 模板名称
cause (str | None) – 用户定义的创建/更新索引模板原因
create (bool | None) – 若为true,此请求不能替换或更新现有索引模板
index_patterns (str | Sequence[str] | None) – 用于在创建期间匹配索引名称的通配符表达式数组
master_timeout (str | Literal[-1] | ~typing.Literal[0] | None) – 等待连接主节点的超时时间。如果在超时前未收到响应,请求将失败并返回错误
order (int | None) – 当索引匹配多个模板时,Elasticsearch应用此模板的顺序。 ‘order’值较低的模板先合并。’order’值较高的模板后合并,覆盖较低值的模板
version (int | None) – 用于外部管理索引模板的版本号。此数值不是由Elasticsearch自动生成的。 要取消设置版本,替换模板时不指定版本号
error_trace (bool | None)
human (bool | None)
pretty (bool | None)
- Return type:
- recovery(*, index=None, active_only=None, allow_no_indices=None, detailed=None, error_trace=None, expand_wildcards=None, filter_path=None, human=None, ignore_unavailable=None, pretty=None)
获取索引恢复信息。 获取一个或多个索引正在进行和已完成的分片恢复信息。 对于数据流,API 返回该流后备索引的信息。
所有恢复状态(无论进行中还是已完成)都保存在集群状态中,可以随时报告。
分片恢复是初始化分片副本的过程,例如从快照恢复主分片或从主分片创建副本分片。 当分片恢复完成时,恢复的分片可用于搜索和索引。
在以下过程中会自动触发恢复:
- 首次创建索引时
- 节点重新加入集群并使用其数据路径中的数据启动任何缺失的主分片副本时
- 从主分片创建新的副本分片时
- 将分片副本重新定位到同一集群中的不同节点时
- 快照恢复操作时
- 克隆、收缩或拆分操作时
您可以使用恢复API或cat恢复API确定分片恢复的原因。
索引恢复API仅报告当前存在于集群中的分片副本的已完成恢复信息。 它只报告每个分片副本的最后一次恢复,不报告早期恢复的历史信息,也不报告不再存在的分片副本的恢复信息。 这意味着如果一个分片副本完成恢复后Elasticsearch将其重新定位到不同节点,则原始恢复的信息不会显示在恢复API中。
https://www.elastic.co/docs/api/doc/elasticsearch/operation/operation-indices-recovery
- Parameters:
index (str | Sequence[str] | None) – 用于限制请求的数据流、索引和别名的逗号分隔列表。支持通配符(*)。 要针对所有数据流和索引,请省略此参数或使用`*`或`_all`。
active_only (bool | None) – 如果为`true`,响应仅包含正在进行的分片恢复。
allow_no_indices (bool | None) – 如果为`false`,当任何通配符表达式、索引别名或`_all`值 仅针对缺失或关闭的索引时,请求返回错误。即使请求针对其他打开的索引, 此行为也适用。
detailed (bool | None) – 如果为`true`,响应包含有关分片恢复的详细信息。
expand_wildcards (Sequence[str | Literal['all', 'closed', 'hidden', 'none', 'open']] | str | ~typing.Literal['all', 'closed', 'hidden', 'none', 'open'] | None) – 通配符模式可以匹配的索引类型。如果请求可以针对数据流, 此参数确定通配符表达式是否匹配隐藏的数据流。支持逗号分隔的值, 例如`open,hidden`。
ignore_unavailable (bool | None) – 如果为`false`,当请求针对缺失或关闭的索引时返回错误。
error_trace (bool | None)
human (bool | None)
pretty (bool | None)
- Return type:
- refresh(*, index=None, allow_no_indices=None, error_trace=None, expand_wildcards=None, filter_path=None, human=None, ignore_unavailable=None, pretty=None)
刷新索引。 刷新操作使最近在一个或多个索引上执行的操作可用于搜索。 对于数据流,API在流的后备索引上运行刷新操作。
默认情况下,Elasticsearch每秒定期刷新索引,但仅限于在过去30秒内收到过搜索请求的索引。 您可以使用
index.refresh_interval设置更改此默认间隔。刷新请求是同步的,在刷新操作完成之前不会返回响应。
刷新操作资源密集。 为确保集群性能良好,建议尽可能等待Elasticsearch的定期刷新,而不是执行显式刷新。
如果您的应用程序工作流程索引文档然后运行搜索以检索索引文档,建议使用索引API的
refresh=wait_for查询参数选项。 此选项确保索引操作在运行搜索之前等待定期刷新。https://www.elastic.co/docs/api/doc/elasticsearch/operation/operation-indices-refresh
- Parameters:
index (str | Sequence[str] | None) – 用于限制请求的数据流、索引和别名的逗号分隔列表。支持通配符(*)。 要针对所有数据流和索引,请省略此参数或使用`*`或`_all`。
allow_no_indices (bool | None) – 如果为`false`,当任何通配符表达式、索引别名或`_all`值 仅针对缺失或关闭的索引时,请求返回错误。即使请求针对其他打开的索引, 此行为也适用。
expand_wildcards (Sequence[str | Literal['all', 'closed', 'hidden', 'none', 'open']] | str | ~typing.Literal['all', 'closed', 'hidden', 'none', 'open'] | None) – 通配符模式可以匹配的索引类型。如果请求可以针对数据流, 此参数确定通配符表达式是否匹配隐藏的数据流。支持逗号分隔的值, 例如`open,hidden`。
ignore_unavailable (bool | None) – 如果为`false`,当请求针对缺失或关闭的索引时返回错误。
error_trace (bool | None)
human (bool | None)
pretty (bool | None)
- Return type:
- reload_search_analyzers(*, index, allow_no_indices=None, error_trace=None, expand_wildcards=None, filter_path=None, human=None, ignore_unavailable=None, pretty=None, resource=None)
重新加载搜索分析器。 重新加载索引的搜索分析器及其资源。 对于数据流,API重新加载流的后备索引的搜索分析器和资源。
重要提示:重新加载搜索分析器后,您应该清除请求缓存以确保它不包含来自分析器先前版本的响应。
您可以使用重新加载搜索分析器API来获取搜索分析器的
synonym_graph或synonym标记过滤器中使用的同义词文件的更改。 要符合条件,标记过滤器必须具有updateable标志为true并且仅在搜索分析器中使用。注意:此API不为索引的每个分片执行重新加载。 相反,它为包含索引分片的每个节点执行重新加载。 因此,API返回的总分片计数可能与索引分片数量不同。 因为重新加载会影响每个具有索引分片的节点,所以在使用此API之前,必须在集群中的每个数据节点(包括不包含分片副本的节点)上更新同义词文件。 这确保同义词文件在集群中各处更新,以防将来重新定位分片。
- Parameters:
allow_no_indices (bool | None) – 是否忽略通配符索引表达式解析为无具体索引的情况 (包括`_all`字符串或未指定索引时)
expand_wildcards (Sequence[str | Literal['all', 'closed', 'hidden', 'none', 'open']] | str | ~typing.Literal['all', 'closed', 'hidden', 'none', 'open'] | None) – 是否将通配符表达式扩展为打开、关闭或两者兼有的具体索引
ignore_unavailable (bool | None) – 当指定的具体索引不可用时(缺失或关闭)是否忽略
resource (str | None) – 如果适用,从中重新加载分析器的已更改资源
error_trace (bool | None)
human (bool | None)
pretty (bool | None)
- Return type:
- remove_block(*, index, block, allow_no_indices=None, error_trace=None, expand_wildcards=None, filter_path=None, human=None, ignore_unavailable=None, master_timeout=None, pretty=None, timeout=None)
移除索引块。
从索引中移除索引块。 索引块通过阻止特定操作类型来限制对索引允许的操作。
https://www.elastic.co/docs/api/doc/elasticsearch/operation/operation-indices-remove-block
- Parameters:
index (str) – 用于限制请求的索引名称的逗号分隔列表或通配符表达式。默认情况下, 您必须明确指定要从中移除块的索引。要允许从具有`_all`、*`或其他通配符表达式的索引中移除块, 请将`action.destructive_requires_name`设置更改为`false。您可以在`elasticsearch.yml` 文件中或使用集群更新设置API更新此设置。
block (str | Literal['metadata', 'read', 'read_only', 'write']) – 要从索引中移除的块类型。
allow_no_indices (bool | None) – 如果为`false`,当任何通配符表达式、索引别名或`_all`值 仅针对缺失或关闭的索引时,请求返回错误。即使请求针对其他打开的索引, 此行为也适用。例如,针对`foo*,bar*`的请求如果存在以`foo`开头的索引但没有以`bar`开头的索引, 则返回错误。
expand_wildcards (Sequence[str | Literal['all', 'closed', 'hidden', 'none', 'open']] | str | ~typing.Literal['all', 'closed', 'hidden', 'none', 'open'] | None) – 通配符模式可以匹配的索引类型。 如果请求可以针对数据流,此参数确定通配符表达式是否匹配隐藏的数据流。 支持逗号分隔的值,例如`open,hidden`。
ignore_unavailable (bool | None) – 如果为`false`,当请求针对缺失或关闭的索引时返回错误。
master_timeout (str | Literal[-1] | ~typing.Literal[0] | None) – 等待主节点的时间段。如果主节点在超时到期之前不可用, 请求失败并返回错误。也可以设置为`-1`表示请求不应超时。
timeout (str | Literal[-1] | ~typing.Literal[0] | None) – 更新集群元数据后等待集群中所有相关节点响应的时间段。 如果在超时到期之前未收到响应,集群元数据更新仍会应用但响应将指示它未被完全确认。 也可以设置为`-1`表示请求不应超时。
error_trace (bool | None)
human (bool | None)
pretty (bool | None)
- Return type:
- resolve_cluster(*, name=None, allow_no_indices=None, error_trace=None, expand_wildcards=None, filter_path=None, human=None, ignore_throttled=None, ignore_unavailable=None, pretty=None, timeout=None)
解析集群。
解析指定的索引表达式以返回有关每个集群的信息,包括本地"查询"集群(如果包含)。 如果未提供索引表达式,API将返回查询集群上配置的所有远程集群的信息。
在进行跨集群搜索之前,此端点非常有用,以确定应包含在搜索中的远程集群。
您可以使用与此端点相同的索引表达式进行跨集群搜索。 此端点也支持索引和集群排除。
对于索引表达式中的每个集群,返回以下信息:
- 查询("本地")集群当前是否连接到索引表达式中指定的每个远程集群。请注意,与
remote/info端点不同,此端点会主动尝试联系远程集群。 - 每个远程集群是否配置为
skip_unavailable为true或false。 - 该集群上是否有任何索引、别名或数据流匹配索引表达式。
- 执行跨集群搜索时是否可能返回错误(包括如果您没有查询索引的权限时的任何授权错误)。
- 集群版本信息,包括Elasticsearch服务器版本。
例如,
GET /_resolve/cluster/my-index-*,cluster*:my-index-*返回有关本地集群和所有以别名cluster*开头的远程配置集群的信息。 每个集群返回有关其是否有任何索引、别名或数据流匹配my-index-*的信息。向后兼容性说明
无索引表达式的查询功能是在8.18版本中添加的,因此当 查询比该版本更旧的远程集群时,本地集群将发送索引 表达式
dummy*给那些远程集群。因此,如果发生错误,您可能会看到 对该索引表达式的引用,即使您没有请求它。如果它导致问题,您可以 改为包含像*:*这样的索引表达式来绕过该问题。在跨集群搜索之前使用此端点的优势
在以下情况下,您可能希望从搜索中排除集群或索引:
- 远程集群当前未连接且配置为
skip_unavailable=false。在这些条件下运行跨集群搜索将导致整个搜索失败。 - 集群没有匹配索引表达式的索引、别名或数据流(或者您的用户没有搜索它们的权限)。例如,假设您的索引表达式是
logs*,remote1:logs*而remote1集群没有匹配logs*的索引、别名或数据流。在这种情况下,如果您在跨集群搜索中包含该集群,该集群将不会返回任何结果。 - 索引表达式(结合您指定的任何查询参数)在执行搜索时可能会引发异常。在这些情况下,
_resolve/cluster响应中的"error"字段将存在。(这也是显示安全/权限错误的地方。) - 远程集群是较旧版本,不支持您想在搜索中使用的功能。
测试远程集群的可用性
remote/info端点通常用于测试"本地"集群(被查询的集群)是否连接到其远程集群,但它不一定反映远程集群是否可用。 远程集群可能可用,而本地集群当前未连接到它。您可以使用
_resolve/clusterAPI尝试重新连接到远程集群。 例如使用GET _resolve/cluster或GET _resolve/cluster/*:*。 响应中的connected字段将指示是否成功。 如果(重新)建立了连接,这也将导致remote/info端点现在显示连接状态。https://www.elastic.co/docs/api/doc/elasticsearch/operation/operation-indices-resolve-cluster
- Parameters:
name (str | Sequence[str] | None) – 要解析的索引、别名和数据流的名称或索引模式的逗号分隔列表。 可以使用`<cluster>`:<name>`语法指定远程集群上的资源。 也支持索引和集群排除(例如-cluster1:*`)。如果未指定索引表达式, 则返回有关本地集群上配置的所有远程集群的信息而不进行任何索引匹配
allow_no_indices (bool | None) – 如果为false,当任何通配符表达式、索引别名或`_all`值 仅针对缺失或关闭的索引时,请求返回错误。即使请求针对其他打开的索引, 此行为也适用。例如,针对`foo*,bar*`的请求如果存在以`foo`开头的索引但没有以`bar`开头的索引, 则返回错误。注意:此选项仅在指定索引表达式时支持。 如果向不采用索引表达式的`_resolve/cluster`API端点指定索引选项, 您将收到错误。
expand_wildcards (Sequence[str | Literal['all', 'closed', 'hidden', 'none', 'open']] | str | ~typing.Literal['all', 'closed', 'hidden', 'none', 'open'] | None) – 通配符模式可以匹配的索引类型。如果请求可以针对数据流, 此参数确定通配符表达式是否匹配隐藏的数据流。支持逗号分隔的值, 例如`open,hidden`。注意:此选项仅在指定索引表达式时支持。 如果向不采用索引表达式的`_resolve/cluster`API端点指定索引选项, 您将收到错误。
ignore_throttled (bool | None) – 如果为true,当冻结时忽略具体、扩展或别名索引。 注意:此选项仅在指定索引表达式时支持。如果向不采用索引表达式的 `_resolve/cluster`API端点指定索引选项,您将收到错误。
ignore_unavailable (bool | None) – 如果为false,当请求针对缺失或关闭的索引时返回错误。 注意:此选项仅在指定索引表达式时支持。如果向不采用索引表达式的 `_resolve/cluster`API端点指定索引选项,您将收到错误。
timeout (str | Literal[-1] | ~typing.Literal[0] | None) – 等待远程集群响应的最长时间。如果远程集群在此超时期间内未响应, API响应将显示集群为未连接状态并包含请求超时的错误消息。 默认超时未设置,查询可以持续网络层配置等待未响应远程集群的时间 (通常为30秒)。
error_trace (bool | None)
human (bool | None)
pretty (bool | None)
- Return type:
- 查询("本地")集群当前是否连接到索引表达式中指定的每个远程集群。请注意,与
- resolve_index(*, name, allow_no_indices=None, error_trace=None, expand_wildcards=None, filter_path=None, human=None, ignore_unavailable=None, pretty=None)
解析索引。 解析索引、别名和数据流的名称和/或索引模式。 支持多种模式和远程集群。
https://www.elastic.co/docs/api/doc/elasticsearch/operation/operation-indices-resolve-index
- Parameters:
name (str | Sequence[str]) – 要解析的索引、别名和数据流的逗号分隔名称或索引模式。 可以使用 <cluster>:<name> 语法指定远程集群上的资源。
allow_no_indices (bool | None) – 如果为 false,当任何通配符表达式、索引别名或 _all 值 仅指向缺失或关闭的索引时,请求将返回错误。即使请求同时指向其他打开的索引, 此行为也适用。例如,针对 foo*,bar* 的请求如果存在以 foo 开头的索引 但没有以 bar 开头的索引,则会返回错误。
expand_wildcards (Sequence[str | Literal['all', 'closed', 'hidden', 'none', 'open']] | str | ~typing.Literal['all', 'closed', 'hidden', 'none', 'open'] | None) – 通配符模式可以匹配的索引类型。如果请求可以针对数据流, 此参数决定通配符表达式是否匹配隐藏的数据流。支持逗号分隔的值, 例如 open,hidden。
ignore_unavailable (bool | None) – 如果为 false,当请求指向缺失或关闭的索引时, 将返回错误。
error_trace (bool | None)
human (bool | None)
pretty (bool | None)
- Return type:
- rollover(*, alias, new_index=None, aliases=None, conditions=None, dry_run=None, error_trace=None, filter_path=None, human=None, lazy=None, mappings=None, master_timeout=None, pretty=None, settings=None, timeout=None, wait_for_active_shards=None, body=None)
滚动到新索引。 提示:建议使用索引生命周期滚动操作来自动化滚动过程。
滚动API为数据流或索引别名创建新索引。 API行为取决于滚动目标。
滚动数据流
如果滚动数据流,API会为数据流创建新的写入索引。 数据流之前的写入索引变为常规后备索引。 滚动还会增加数据流的生成号。
滚动带有写入索引的索引别名
提示:在Elasticsearch 7.9之前,通常会使用带有写入索引的索引别名来管理时间序列数据。 数据流取代了这一功能,需要更少的维护,并自动与数据层集成。
如果一个索引别名指向多个索引,其中一个索引必须是写入索引。 滚动API会为别名创建一个新的写入索引,并将
is_write_index设置为true。 API还会将之前写入索引的is_write_index设置为false。滚动只有一个索引的索引别名
如果滚动指向单个索引的索引别名,API会为别名创建新索引,并从别名中移除原始索引。
注意:滚动会创建新索引,并受
wait_for_active_shards设置的影响。递增别名索引名称
滚动索引别名时,可以指定新索引的名称。 如果不指定名称且当前索引以
-和数字结尾,例如my-index-000001或my-index-3, 新索引名称会递增该数字。例如,如果滚动别名的当前索引是my-index-000001, 滚动会创建名为my-index-000002的新索引。 无论之前索引名称如何,这个数字始终是六位并用零填充。如果对时间序列数据使用索引别名,可以在索引名称中使用日期数学来跟踪滚动日期。 例如,可以创建指向名为
<my-index-{now/d}-000001>索引的别名。 如果在2099年5月6日创建索引,索引名称为my-index-2099.05.06-000001。 如果在2099年5月7日滚动别名,新索引名称为my-index-2099.05.07-000002。https://www.elastic.co/docs/api/doc/elasticsearch/operation/operation-indices-rollover
- Parameters:
alias (str) – 要滚动的数据流或索引别名的名称。
new_index (str | None) – 要创建的索引名称。支持日期数学。数据流不支持此参数。
aliases (Mapping[str, Mapping[str, Any]] | None) – 目标索引的别名。数据流不支持此参数。
conditions (Mapping[str, Any] | None) – 滚动条件。如果指定,Elasticsearch仅在当前索引满足这些条件时执行滚动。 如果未指定此参数,Elasticsearch无条件执行滚动。 如果指定了条件,其中至少一个必须是`max_*`条件。 当任何`max_*`条件满足且所有`min_*`条件都满足时,索引将滚动。
dry_run (bool | None) – 如果为`true`,检查当前索引是否满足指定条件但不执行滚动。
lazy (bool | None) – 如果设置为true,滚动操作将仅标记数据流以指示需要在下次写入时滚动。 仅允许用于数据流。
mappings (Mapping[str, Any] | None) – 索引中字段的映射。如果指定,此映射可以包括字段名、字段数据类型和映射参数。
master_timeout (str | Literal[-1] | ~typing.Literal[0] | None) – 等待连接到主节点的时间。如果在超时前未收到响应, 请求将失败并返回错误。
timeout (str | Literal[-1] | ~typing.Literal[0] | None) – 等待响应的时间。如果在超时前未收到响应, 请求将失败并返回错误。
wait_for_active_shards (int | str | Literal['all', 'index-setting'] | None) – 操作前必须激活的分片副本数。 可设置为`all`或任何不超过索引总分片数(number_of_replicas+1)的正整数。
error_trace (bool | None)
human (bool | None)
pretty (bool | None)
- Return type:
- segments(*, index=None, allow_no_indices=None, error_trace=None, expand_wildcards=None, filter_path=None, human=None, ignore_unavailable=None, pretty=None)
获取索引段信息。 获取索引分片中Lucene段的底层信息。 对于数据流,API返回流后备索引的信息。
https://www.elastic.co/docs/api/doc/elasticsearch/operation/operation-indices-segments
- Parameters:
index (str | Sequence[str] | None) – 用于限制请求的数据流、索引和别名的逗号分隔列表。 支持通配符(*)。要针对所有数据流和索引,省略此参数或使用`*`或`_all`。
allow_no_indices (bool | None) – 如果为`false`,当任何通配符表达式、索引别名或`_all`值 仅指向缺失或关闭的索引时,请求将返回错误。即使请求同时指向其他打开的索引, 此行为也适用。
expand_wildcards (Sequence[str | Literal['all', 'closed', 'hidden', 'none', 'open']] | str | ~typing.Literal['all', 'closed', 'hidden', 'none', 'open'] | None) – 通配符模式可以匹配的索引类型。如果请求可以针对数据流, 此参数决定通配符表达式是否匹配隐藏的数据流。支持逗号分隔的值, 例如`open,hidden`。
ignore_unavailable (bool | None) – 如果为`false`,当请求指向缺失或关闭的索引时, 将返回错误。
error_trace (bool | None)
human (bool | None)
pretty (bool | None)
- Return type:
- shard_stores(*, index=None, allow_no_indices=None, error_trace=None, expand_wildcards=None, filter_path=None, human=None, ignore_unavailable=None, pretty=None, status=None)
获取索引分片存储信息。 获取一个或多个索引中副本分片的存储信息。 对于数据流,API检索流后备索引的存储信息。
索引分片存储API返回以下信息:
- 每个副本分片所在的节点。
- 每个副本分片的分配ID。
- 每个副本分片的唯一ID。
- 打开分片索引时或之前失败时遇到的任何错误。
默认情况下,API仅返回未分配或有一个或多个未分配副本分片的主分片的存储信息。
https://www.elastic.co/docs/api/doc/elasticsearch/operation/operation-indices-shard-stores
- Parameters:
allow_no_indices (bool | None) – 如果为false,当任何通配符表达式、索引别名或_all值 仅指向缺失或关闭的索引时,请求将返回错误。即使请求同时指向其他打开的索引, 此行为也适用。
expand_wildcards (Sequence[str | Literal['all', 'closed', 'hidden', 'none', 'open']] | str | ~typing.Literal['all', 'closed', 'hidden', 'none', 'open'] | None) – 通配符模式可以匹配的索引类型。如果请求可以针对数据流, 此参数决定通配符表达式是否匹配隐藏的数据流。
ignore_unavailable (bool | None) – 如果为true,缺失或关闭的索引不会包含在响应中。
status (Sequence[str | Literal['all', 'green', 'red', 'yellow']] | str | ~typing.Literal['all', 'green', 'red', 'yellow'] | None) – 用于限制请求的分片健康状态列表。
error_trace (bool | None)
human (bool | None)
pretty (bool | None)
- Return type:
- shrink(*, index, target, aliases=None, error_trace=None, filter_path=None, human=None, master_timeout=None, pretty=None, settings=None, timeout=None, wait_for_active_shards=None, body=None)
收缩索引。 将索引收缩为具有较少主分片的新索引。
在收缩索引前:
- 索引必须为只读。
- 索引中每个分片的副本必须位于同一节点上。
- 索引的健康状态必须为绿色。
为了便于分片分配,建议同时移除索引的副本分片。 之后可以在收缩操作中重新添加副本分片。
目标索引中请求的主分片数量必须是源索引分片数量的因数。 例如,具有8个主分片的索引可以收缩为4、2或1个主分片,具有15个主分片的索引可以收缩为5、3或1个主分片。 如果索引的分片数量是质数,则只能收缩为单个主分片。 收缩前,索引中每个分片(主分片或副本分片)的副本必须位于同一节点上。
数据流上的当前写入索引不能被收缩。要收缩当前写入索引,必须先滚动数据流以创建新的写入索引,然后才能收缩之前的写入索引。
收缩操作:
- 创建与源索引定义相同但主分片数量较少的目标索引。
- 将源索引的段硬链接到目标索引。如果文件系统不支持硬链接,则所有段都会被复制到新索引,这是一个更耗时的过程。此外,如果使用多个数据路径,不同数据路径上的分片如果不在同一磁盘上,则需要完整复制段文件,因为硬链接不能跨磁盘工作。
- 恢复目标索引,就像它是刚刚重新打开的关闭索引一样。将分片恢复到
.routing.allocation.initial_recovery._id索引设置。
重要:索引只有在满足以下要求时才能被收缩:
- 目标索引必须不存在。
- 源索引的主分片数量必须多于目标索引。
- 目标索引的主分片数量必须是源索引主分片数量的因数。源索引的主分片数量必须多于目标索引。
- 索引在所有将被收缩到目标索引单个分片的分片中不能包含超过2,147,483,519个文档,因为这是单个分片能容纳的最大文档数。
- 处理收缩过程的节点必须有足够的空闲磁盘空间来容纳现有索引的第二个副本。
https://www.elastic.co/docs/api/doc/elasticsearch/operation/operation-indices-shrink
- Parameters:
index (str) – 要收缩的源索引名称。
target (str) – 要创建的目标索引名称。
aliases (Mapping[str, Mapping[str, Any]] | None) – 键是别名名称。索引别名名称支持日期数学。
master_timeout (str | Literal[-1] | ~typing.Literal[0] | None) – 等待连接到主节点的时间。如果在超时前未收到响应, 请求将失败并返回错误。
timeout (str | Literal[-1] | ~typing.Literal[0] | None) – 等待响应的时间。如果在超时前未收到响应, 请求将失败并返回错误。
wait_for_active_shards (int | str | Literal['all', 'index-setting'] | None) – 操作前必须激活的分片副本数。 可设置为`all`或任何不超过索引总分片数(number_of_replicas+1)的正整数。
error_trace (bool | None)
human (bool | None)
pretty (bool | None)
- Return type:
- simulate_index_template(*, name, cause=None, create=None, error_trace=None, filter_path=None, human=None, include_defaults=None, master_timeout=None, pretty=None)
模拟索引。 从现有索引模板获取将应用于指定索引的索引配置。
- Parameters:
name (str) – 要模拟的索引名称
cause (str | None) – 用于模拟目的的用户定义原因,用于干运行创建新模板
create (bool | None) – 我们可选地在请求体中定义的索引模板是否应仅在新增时干运行添加,或者也可以替换现有模板
include_defaults (bool | None) – 如果为true,则返回索引模板的所有相关默认配置
master_timeout (str | Literal[-1] | ~typing.Literal[0] | None) – 等待连接到主节点的时间。如果在超时到期前未收到响应,则请求失败并返回错误
error_trace (bool | None)
human (bool | None)
pretty (bool | None)
- Return type:
- simulate_template(*, name=None, allow_auto_create=None, cause=None, composed_of=None, create=None, data_stream=None, deprecated=None, error_trace=None, filter_path=None, human=None, ignore_missing_component_templates=None, include_defaults=None, index_patterns=None, master_timeout=None, meta=None, pretty=None, priority=None, template=None, version=None, body=None)
模拟索引模板。 获取特定索引模板将应用的索引配置。
https://www.elastic.co/docs/api/doc/elasticsearch/operation/operation-indices-simulate-template
- Parameters:
name (str | None) – 要模拟的索引模板名称。要在将模板配置添加到集群之前测试它,请省略此参数并在请求体中指定模板配置
allow_auto_create (bool | None) – 此设置覆盖`action.auto_create_index`集群设置的值。如果在模板中设置为`true`,则即使通过`actions.auto_create_index`禁用索引自动创建,也可以使用该模板自动创建索引。如果设置为`false`,则必须始终显式创建与模板匹配的索引或数据流,并且永远不会自动创建
cause (str | None) – 用于模拟目的的用户定义原因,用于干运行创建新模板
composed_of (Sequence[str] | None) – 组件模板名称的有序列表。组件模板按指定顺序合并,意味着最后指定的组件模板具有最高优先级
create (bool | None) – 如果为true,则仅在没有现有模板匹配相同索引模式时使用请求体中的模板。如果为false,则模拟使用具有最高优先级的模板。请注意,在这两种情况下,模板都不会永久添加或更新;它仅用于模拟
data_stream (Mapping[str, Any] | None) – 如果包含此对象,则模板用于创建数据流及其支持索引。支持空对象。数据流需要具有`data_stream`对象的匹配索引模板
deprecated (bool | None) – 将此索引模板标记为已弃用。当创建或更新使用已弃用组件的非弃用索引模板时,Elasticsearch将发出弃用警告
ignore_missing_component_templates (Sequence[str] | None) – 当索引模板引用可能不存在的组件模板时,可以使用ignore_missing_component_templates配置选项
include_defaults (bool | None) – 如果为true,则返回索引模板的所有相关默认配置
index_patterns (str | Sequence[str] | None) – 用于在创建期间匹配数据流和索引名称的通配符(*)表达式数组
master_timeout (str | Literal[-1] | ~typing.Literal[0] | None) – 等待连接到主节点的时间。如果在超时到期前未收到响应,则请求失败并返回错误
meta (Mapping[str, Any] | None) – 关于索引模板的可选用户元数据。可以包含任何内容。此映射不是由Elasticsearch自动生成的
priority (int | None) – 确定创建新数据流或索引时的索引模板优先级的优先级。选择具有最高优先级的索引模板。如果未指定优先级,则模板被视为优先级0(最低优先级)。此数字不是由Elasticsearch自动生成的
template (Mapping[str, Any] | None) – 要应用的模板。它可以可选地包含`aliases`、`mappings`或`settings`配置
version (int | None) – 用于外部管理索引模板的版本号。此数字不是由Elasticsearch自动生成的
error_trace (bool | None)
human (bool | None)
pretty (bool | None)
- Return type:
- split(*, index, target, aliases=None, error_trace=None, filter_path=None, human=None, master_timeout=None, pretty=None, settings=None, timeout=None, wait_for_active_shards=None, body=None)
拆分索引。 将索引拆分为具有更多主分片的新索引。
-
在拆分索引之前:
-
索引必须为只读。
-
集群健康状态必须为绿色。
您可以使用添加索引块API通过以下请求使索引变为只读:
PUT /my_source_index/_block/write数据流上的当前写入索引不能被拆分。 为了拆分当前写入索引,必须首先滚动数据流以创建新的写入索引,然后才能拆分先前的写入索引。
索引可以拆分的次数(以及每个原始分片可以拆分为的分片数量)由`index.number_of_routing_shards`设置决定。 路由分片数量指定了用于通过一致性哈希在分片间分发文档的内部哈希空间。 例如,具有设置为30(5 x 2 x 3)的`number_of_routing_shards`的5分片索引可以按2或3的因子拆分。
拆分操作:
- 创建一个与源索引定义相同但具有更多主分片的新目标索引
- 将段从源索引硬链接到目标索引。如果文件系统不支持硬链接,则所有段都将复制到新索引中,这是一个更耗时的过程
- 在创建低级文件后,再次哈希所有文档以删除属于不同分片的文档
- 恢复目标索引,就像它是刚刚重新打开的已关闭索引
重要提示:索引只有在满足以下要求时才能拆分:
- 目标索引必须不存在
- 源索引的主分片必须少于目标索引
- 目标索引中的主分片数量必须是源索引中主分片数量的倍数
- 处理拆分过程的节点必须有足够的可用磁盘空间来容纳现有索引的第二个副本
https://www.elastic.co/docs/api/doc/elasticsearch/operation/operation-indices-split
- Parameters:
index (str) – 要拆分的源索引名称
target (str) – 要创建的目标索引名称
master_timeout (str | Literal[-1] | ~typing.Literal[0] | None) – 等待连接到主节点的时间。如果在超时到期前未收到响应,则请求失败并返回错误
timeout (str | Literal[-1] | ~typing.Literal[0] | None) – 等待响应的时间。如果在超时到期前未收到响应,则请求失败并返回错误
wait_for_active_shards (int | str | Literal['all', 'index-setting'] | None) – 在继续操作之前必须激活的分片副本数量。设置为`all`或任何正整数,最大为索引中的总分片数(number_of_replicas+1)
error_trace (bool | None)
human (bool | None)
pretty (bool | None)
- Return type:
-
- stats(*, index=None, metric=None, completion_fields=None, error_trace=None, expand_wildcards=None, fielddata_fields=None, fields=None, filter_path=None, forbid_closed_indices=None, groups=None, human=None, include_segment_file_sizes=None, include_unloaded_segments=None, level=None, pretty=None)
获取索引统计信息。 对于数据流,API检索流的支持索引的统计信息。
默认情况下,返回的统计信息是索引级别的,具有`primaries`和`total`聚合。 `primaries`是仅针对主分片的值。 `total`是主分片和副本分片的累计值。
要获取分片级别的统计信息,请将`level`参数设置为`shards`。
注意:当移动到另一个节点时,分片的分片级别统计信息将被清除。 尽管分片不再是节点的一部分,但该节点保留分片贡献的任何节点级别统计信息。
https://www.elastic.co/docs/api/doc/elasticsearch/operation/operation-indices-stats
- Parameters:
index (str | Sequence[str] | None) – 逗号分隔的索引名称列表;使用`_all`或空字符串对所有索引执行操作
completion_fields (str | Sequence[str] | None) – 逗号分隔的字段列表或通配符表达式,包含在fielddata和建议统计信息中
expand_wildcards (Sequence[str | Literal['all', 'closed', 'hidden', 'none', 'open']] | str | ~typing.Literal['all', 'closed', 'hidden', 'none', 'open'] | None) – 通配符模式可以匹配的索引类型。如果请求可以针对数据流,则此参数确定通配符表达式是否匹配隐藏的数据流。支持逗号分隔的值,例如`open,hidden`
fielddata_fields (str | Sequence[str] | None) – 逗号分隔的字段列表或通配符表达式,包含在fielddata统计信息中
fields (str | Sequence[str] | None) – 逗号分隔的字段列表或通配符表达式,包含在统计信息中
forbid_closed_indices (bool | None) – 如果为true,则不从关闭的索引收集统计信息
include_segment_file_sizes (bool | None) – 如果为true,则调用报告每个Lucene索引文件的聚合磁盘使用情况(仅在请求段统计信息时适用)
include_unloaded_segments (bool | None) – 如果为true,则响应包括未加载到内存中的段的信息
level (str | Literal['cluster', 'indices', 'shards'] | None) – 指示统计信息是在集群、索引还是分片级别聚合
error_trace (bool | None)
human (bool | None)
pretty (bool | None)
- Return type:
- update_aliases(*, actions=None, error_trace=None, filter_path=None, human=None, master_timeout=None, pretty=None, timeout=None, body=None)
创建或更新别名。 将数据流或索引添加到别名。
https://www.elastic.co/docs/api/doc/elasticsearch/operation/operation-indices-update-aliases
- validate_query(*, index=None, all_shards=None, allow_no_indices=None, analyze_wildcard=None, analyzer=None, default_operator=None, df=None, error_trace=None, expand_wildcards=None, explain=None, filter_path=None, human=None, ignore_unavailable=None, lenient=None, pretty=None, q=None, query=None, rewrite=None, body=None)
验证查询。 在不执行查询的情况下验证查询的有效性。
https://www.elastic.co/docs/api/doc/elasticsearch/operation/operation-indices-validate-query
- Parameters:
index (str | Sequence[str] | None) – 要搜索的数据流、索引和别名的逗号分隔列表。 支持通配符(*)。若要搜索所有数据流或索引,可省略此参数或使用`*`或`_all`。
all_shards (bool | None) – 若为`true`,将在所有分片上执行验证,而非每个索引随机选择一个分片。
allow_no_indices (bool | None) – 若为`false`,当任何通配符表达式、索引别名或`_all`值仅指向缺失或关闭的索引时,请求将返回错误。 即使请求同时指向其他打开的索引,此行为依然适用。
analyze_wildcard (bool | None) – 若为`true`,将分析通配符和前缀查询。
analyzer (str | None) – 用于查询字符串的分析器。此参数仅在指定了`q`查询字符串参数时可用。
default_operator (str | Literal['and', 'or'] | None) – 查询字符串的默认运算符:AND`或`OR。
df (str | None) – 当查询字符串中未指定字段前缀时使用的默认字段。此参数仅在指定了`q`查询字符串参数时可用。
expand_wildcards (Sequence[str | Literal['all', 'closed', 'hidden', 'none', 'open']] | str | ~typing.Literal['all', 'closed', 'hidden', 'none', 'open'] | None) – 通配符模式可匹配的索引类型。如果请求可以指向数据流,此参数决定通配符表达式是否匹配隐藏数据流。 支持逗号分隔值,例如`open,hidden`。
explain (bool | None) – 若为`true`,当发生错误时响应将返回详细信息。
ignore_unavailable (bool | None) – 若为`false`,当请求指向缺失或关闭的索引时将返回错误。
lenient (bool | None) – 若为`true`,将忽略查询字符串中基于格式的查询失败(例如向数值字段提供文本)。
q (str | None) – 使用Lucene查询字符串语法的查询。
rewrite (bool | None) – 若为`true`,将返回更详细的解释,显示实际将执行的Lucene查询。
error_trace (bool | None)
human (bool | None)
pretty (bool | None)
- Return type: