Python Elasticsearch 客户端
  • Elasticsearch API
    • Elasticsearch
    • 异步搜索(Async Search)
      • AsyncSearchClient
        • AsyncSearchClient.delete()
        • AsyncSearchClient.get()
        • AsyncSearchClient.status()
        • AsyncSearchClient.submit()
    • 自动扩缩容(Autoscaling)
    • Cat
    • 跨集群复制(CCR)
    • 集群(Cluster)
    • 连接器(Connector)
    • 悬挂索引(Dangling Indices)
    • Enrich 策略
    • 事件查询语言(EQL)
    • ES|QL
    • Fleet
    • 图探索(Graph Explore)
    • 索引生命周期管理(ILM)
    • 索引(Indices)
    • 推理(Inference)
    • Ingest 管道
    • 许可证
    • Logstash
    • 迁移
    • 机器学习(ML)
    • 监控(Monitoring)
    • 节点(Nodes)
    • 查询规则(Query rules)
    • Rollup 索引
    • 搜索应用
    • 可搜索快照(Searchable Snapshots)
    • 安全
    • 关闭(Shutdown)
    • 模拟(Simulate)
    • 快照生命周期管理(SLM)
    • 快照(Snapshots)
    • 可快照特性
    • SQL
    • 同义词
    • TLS/SSL
    • 任务(Tasks)
    • 文本结构
    • 转换(Transforms)
    • 监视器(Watcher)
    • X-Pack
  • ES|QL 查询构建器
  • DSL(领域特定语言)
  • 辅助工具(Helpers)
  • 异常与警告

Async

  • 异步 Elasticsearch API
  • 异步 DSL
  • 异步辅助函数
Python Elasticsearch 客户端
  • Elasticsearch API
  • 异步搜索(Async Search)
  • View page source

异步搜索(Async Search)

class elasticsearch.client.AsyncSearchClient

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

from elasticsearch import Elasticsearch

# Create the client instance
client = Elasticsearch(...)
# Use the async_search client
client.async_search.<method>(...)
delete(*, id, error_trace=None, filter_path=None, human=None, pretty=None)

删除一个异步搜索。

如果异步搜索仍在运行,则会被取消。 否则,已保存的搜索结果将被删除。 如果启用了 Elasticsearch 安全功能,删除特定异步搜索的权限仅限于:提交原始搜索请求的认证用户;拥有 cancel_task 集群权限的用户。

https://www.elastic.co/docs/api/doc/elasticsearch/operation/operation-async-search-submit

Parameters:
  • id (str) – 异步搜索的唯一标识符。

  • error_trace (bool | None)

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

  • human (bool | None)

  • pretty (bool | None)

Return type:

ObjectApiResponse[Any]

get(*, id, error_trace=None, filter_path=None, human=None, keep_alive=None, pretty=None, typed_keys=None, wait_for_completion_timeout=None)

获取异步搜索结果。

检索先前提交的异步搜索请求的结果。 如果启用了 Elasticsearch 安全功能,访问特定异步搜索结果的权限仅限于提交该搜索的用户或 API 密钥。

https://www.elastic.co/docs/api/doc/elasticsearch/operation/operation-async-search-submit

Parameters:
  • id (str) – 异步搜索的唯一标识符。

  • keep_alive (str | Literal[-1] | ~typing.Literal[0] | None) – 异步搜索在集群中可用的时长。 未指定时,将使用对应提交异步请求时设置的 keep_alive 值。 否则可以覆盖该值并延长请求的有效期。当此期限到期时, 如果搜索仍在运行,则会被取消。如果搜索已完成, 其保存的结果将被删除。

  • typed_keys (bool | None) – 指定响应中聚合和建议器名称是否应 以其各自类型为前缀

  • wait_for_completion_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]

status(*, id, error_trace=None, filter_path=None, human=None, keep_alive=None, pretty=None)

获取异步搜索状态。

根据标识符获取先前提交的异步搜索请求的状态,而不检索搜索结果。 如果启用了 Elasticsearch 安全功能,访问特定异步搜索状态的权限仅限于:

  • 提交原始异步搜索请求的用户或 API 密钥。
  • 拥有 monitor 集群权限或更高权限的用户。

https://www.elastic.co/docs/api/doc/elasticsearch/operation/operation-async-search-submit

Parameters:
  • id (str) – 异步搜索的唯一标识符。

  • keep_alive (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]

submit(*, index=None, aggregations=None, aggs=None, allow_no_indices=None, allow_partial_search_results=None, analyze_wildcard=None, analyzer=None, batched_reduce_size=None, ccs_minimize_roundtrips=None, collapse=None, default_operator=None, df=None, docvalue_fields=None, error_trace=None, expand_wildcards=None, explain=None, ext=None, fields=None, filter_path=None, from_=None, highlight=None, human=None, ignore_throttled=None, ignore_unavailable=None, indices_boost=None, keep_alive=None, keep_on_completion=None, knn=None, lenient=None, max_concurrent_shard_requests=None, min_score=None, pit=None, post_filter=None, preference=None, pretty=None, profile=None, q=None, query=None, request_cache=None, rescore=None, rest_total_hits_as_int=None, routing=None, runtime_mappings=None, script_fields=None, search_after=None, search_type=None, seq_no_primary_term=None, size=None, slice=None, sort=None, source=None, source_excludes=None, source_includes=None, stats=None, stored_fields=None, suggest=None, suggest_field=None, suggest_mode=None, suggest_size=None, suggest_text=None, terminate_after=None, timeout=None, track_scores=None, track_total_hits=None, typed_keys=None, version=None, wait_for_completion_timeout=None, body=None)

执行异步搜索。

当结果的主排序是索引字段时,分片会根据该字段的最小值和最大值进行排序。按照请求的排序标准,部分结果会变得可用。

警告:异步搜索不支持仅包含建议部分的滚动或搜索请求。

默认情况下,Elasticsearch 不允许存储超过 10Mb 的异步搜索响应,尝试这样做会导致错误。 可以通过更改集群级设置 search.max_async_search_response_size 来设置存储异步搜索响应的最大允许大小。

https://www.elastic.co/docs/api/doc/elasticsearch/operation/operation-async-search-submit

Parameters:
  • index (str | Sequence[str] | None) – 要搜索的索引名称逗号分隔列表;使用 _all 或 空字符串表示对所有索引执行操作

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

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

  • allow_no_indices (bool | None) – 当通配符索引表达式未解析到具体索引时是否忽略。 (包括 _all 字符串或未指定索引时)

  • allow_partial_search_results (bool | None) – 指示在部分搜索失败或超时时 是否应返回错误

  • analyze_wildcard (bool | None) – 指定是否分析通配符和前缀查询 (默认: false)

  • analyzer (str | None) – 用于查询字符串的分析器

  • batched_reduce_size (int | None) – 影响部分结果可用的频率, 每当分片结果被缩减时就会发生。每当协调节点接收到 一定数量的新分片响应(默认为5)时,就会执行部分缩减。

  • ccs_minimize_roundtrips (bool | None) – 默认值是唯一支持的值。

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

  • default_operator (str | Literal['and', 'or'] | None) – 查询字符串查询的默认运算符(AND 或 OR)

  • df (str | None) – 当查询字符串中未给出字段前缀时使用的默认字段

  • docvalue_fields (Sequence[Mapping[str, Any]] | None) – 通配符(*)模式数组。请求返回匹配这些模式的 字段名称的文档值,位于响应的 hits.fields 属性中。

  • expand_wildcards (Sequence[str | Literal['all', 'closed', 'hidden', 'none', 'open']] | str | ~typing.Literal['all', 'closed', 'hidden', 'none', 'open'] | None) – 是否将通配符表达式扩展到打开的、关闭的或两者兼有的具体索引。

  • explain (bool | None) – 如果为 true,则返回有关命中分数计算的详细信息。

  • ext (Mapping[str, Any] | None) – 由 Elasticsearch 插件定义的搜索扩展配置。

  • fields (Sequence[Mapping[str, Any]] | None) – 通配符(*)模式数组。请求返回匹配这些模式的 字段名称的值,位于响应的 hits.fields 属性中。

  • from – 起始文档偏移量。默认情况下,使用 from 和 size 参数 无法分页超过 10,000 个命中。要分页更多命中,请使用 search_after 参数。

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

  • ignore_throttled (bool | None) – 当限流时是否忽略指定的具体、扩展或别名索引

  • ignore_unavailable (bool | None) – 当不可用时(缺失或关闭)是否忽略指定的具体索引

  • indices_boost (Sequence[Mapping[str, float]] | None) – 提升来自指定索引的文档的 _score。

  • keep_alive (str | Literal[-1] | ~typing.Literal[0] | None) – 指定异步搜索需要保持可用的时长。 在此期限后,正在进行的异步搜索和任何保存的搜索结果将被删除。

  • keep_on_completion (bool | None) – 如果为 true,当搜索在 wait_for_completion_timeout 内完成时, 结果会被存储以供后续检索。

  • knn (Mapping[str, Any] | Sequence[Mapping[str, Any]] | None) – 定义要运行的近似 kNN 搜索。

  • lenient (bool | None) – 指定是否忽略基于格式的查询失败(例如向数字字段提供文本)

  • max_concurrent_shard_requests (int | None) – 此搜索在每个节点上并发执行的 分片请求数。此值应用于限制搜索对集群的影响,以限制并发分片请求数

  • min_score (float | None) – 匹配文档的最低 _score。_score 较低的文档 不会包含在搜索结果和聚合收集的结果中。

  • pit (Mapping[str, Any] | None) – 将搜索限制到某个时间点(PIT)。如果提供了 PIT, 则不能在请求路径中指定 <index>。

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

  • preference (str | None) – 指定应在其上执行操作的节点或分片 (默认: random)

  • profile (bool | None)

  • q (str | None) – Lucene 查询字符串语法中的查询

  • query (Mapping[str, Any] | None) – 使用 Query DSL 定义搜索定义。

  • request_cache (bool | None) – 指定是否对此请求使用请求缓存,默认为 true

  • rescore (Mapping[str, Any] | Sequence[Mapping[str, Any]] | None)

  • rest_total_hits_as_int (bool | None) – 指示 hits.total 在 rest 搜索响应中 应呈现为整数还是对象

  • routing (str | None) – 特定路由值的逗号分隔列表

  • runtime_mappings (Mapping[str, Mapping[str, Any]] | None) – 在搜索请求中定义一个或多个运行时字段。 这些字段优先于同名的映射字段。

  • script_fields (Mapping[str, Mapping[str, Any]] | None) – 为每个命中检索(基于不同字段的)脚本评估。

  • search_after (Sequence[None | bool | float | int | str] | None)

  • search_type (str | Literal['dfs_query_then_fetch', 'query_then_fetch'] | None) – 搜索操作类型

  • seq_no_primary_term (bool | None) – 如果为 true,则返回每个命中最后修改的 序列号和主项。参见乐观并发控制。

  • size (int | None) – 要返回的命中数。默认情况下,使用 from 和 size 参数 无法分页超过 10,000 个命中。要分页更多命中,请使用 search_after 参数。

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

  • sort (Sequence[str | Mapping[str, Any]] | str | Mapping[str, Any] | None)

  • source (bool | Mapping[str, Any] | None) – 指示为匹配文档返回哪些源字段。 这些字段位于搜索响应的 hits._source 属性中。

  • source_excludes (str | Sequence[str] | None) – 要从返回的 _source 字段中排除的字段列表

  • source_includes (str | Sequence[str] | None) – 要从 _source 字段中提取并返回的字段列表

  • stats (Sequence[str] | None) – 与搜索关联的统计组。每个组为其关联的搜索 维护统计聚合。可以使用索引统计 API 检索这些统计信息。

  • stored_fields (str | Sequence[str] | None) – 作为命中一部分返回的存储字段列表。如果未 指定字段,则响应中不包含存储字段。如果指定了此字段, _source 参数默认为 false。可以传递 _source: true 以在搜索 响应中同时返回源字段和存储字段。

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

  • suggest_field (str | None) – 指定用于建议的字段。

  • suggest_mode (str | Literal['always', 'missing', 'popular'] | None) – 指定建议模式

  • suggest_size (int | None) – 响应中返回的建议数量

  • suggest_text (str | None) – 应返回建议的源文本。

  • terminate_after (int | None) – 为每个分片收集的最大文档数。 如果查询达到此限制,Elasticsearch 会提前终止查询。 Elasticsearch 在排序前收集文档。默认为 0,表示 不会提前终止查询执行。

  • timeout (str | None) – 指定等待每个分片响应的超时时间。 如果在超时到期前未收到响应,则请求失败并返回错误。默认为无超时。

  • track_scores (bool | None) – 如果为 true,则计算并返回文档分数,即使 分数不用于排序。

  • track_total_hits (bool | int | None) – 准确计数匹配查询的命中数。 如果为 true,则以一些性能为代价返回确切的命中数。 如果为 false,则响应不包括匹配查询的总命中数。默认为 10,000 命中。

  • typed_keys (bool | None) – 指定响应中聚合和建议器名称是否应 以其各自类型为前缀

  • version (bool | None) – 如果为 true,则返回作为命中一部分的文档版本。

  • wait_for_completion_timeout (str | Literal[-1] | ~typing.Literal[0] | None) – 阻塞并等待直到搜索完成,直到某个超时。 当异步搜索在超时内完成时,响应不会包含 ID,因为结果不会存储在集群中。

  • 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]

Previous Next

© Copyright 2025, Elasticsearch B.V.

Built with Sphinx using a theme provided by Read the Docs.