SQL
- class elasticsearch.client.SqlClient
To use this client, access
client.sql
from anElasticsearch
client. For example:from elasticsearch import Elasticsearch # Create the client instance client = Elasticsearch(...) # Use the sql client client.sql.<method>(...)
- clear_cursor(*, cursor=None, error_trace=None, filter_path=None, human=None, pretty=None, body=None)
清除 SQL 搜索游标。
https://www.elastic.co/docs/api/doc/elasticsearch/operation/operation-sql-clear-cursor
- delete_async(*, id, error_trace=None, filter_path=None, human=None, pretty=None)
删除异步 SQL 搜索。 删除异步 SQL 搜索或存储的同步 SQL 搜索。 如果搜索仍在运行,API 将取消该搜索。
如果启用了 Elasticsearch 安全功能,则只有以下用户可以使用此 API 删除搜索:
- 具有
cancel_task
集群权限的用户。 - 首次提交搜索的用户。
https://www.elastic.co/docs/api/doc/elasticsearch/operation/operation-sql-delete-async
- 具有
- get_async(*, id, delimiter=None, error_trace=None, filter_path=None, format=None, human=None, keep_alive=None, pretty=None, wait_for_completion_timeout=None)
获取异步 SQL 搜索结果。 获取异步 SQL 搜索或存储的同步 SQL 搜索的当前状态和可用结果。
如果启用了 Elasticsearch 安全功能,则只有首次提交 SQL 搜索的用户可以使用此 API 检索搜索。
https://www.elastic.co/docs/api/doc/elasticsearch/operation/operation-sql-get-async
- Parameters:
id (str) – 搜索的标识符。
delimiter (str | None) – CSV 结果的分隔符。API 仅对 CSV 响应支持此参数。
format (str | None) – 响应的格式。必须使用此参数或 Accept HTTP 头指定格式。如果同时指定两者,API 将使用此参数。
keep_alive (str | Literal[-1] | ~typing.Literal[0] | None) – 搜索及其结果的保留期。默认为原始 SQL 搜索的 keep_alive 期限。
wait_for_completion_timeout (str | Literal[-1] | ~typing.Literal[0] | None) – 等待完整结果的期限。默认为无超时,意味着请求将等待完整的搜索结果。
error_trace (bool | None)
human (bool | None)
pretty (bool | None)
- Return type:
- get_async_status(*, id, error_trace=None, filter_path=None, human=None, pretty=None)
获取异步 SQL 搜索状态。 获取异步 SQL 搜索或存储的同步 SQL 搜索的当前状态。
https://www.elastic.co/docs/api/doc/elasticsearch/operation/operation-sql-get-async-status
- query(*, allow_partial_search_results=None, catalog=None, columnar=None, cursor=None, error_trace=None, fetch_size=None, field_multi_value_leniency=None, filter=None, filter_path=None, format=None, human=None, index_using_frozen=None, keep_alive=None, keep_on_completion=None, page_timeout=None, params=None, pretty=None, query=None, request_timeout=None, runtime_mappings=None, time_zone=None, wait_for_completion_timeout=None, body=None)
获取 SQL 搜索结果。 运行 SQL 请求。
https://www.elastic.co/docs/api/doc/elasticsearch/operation/operation-sql-query
- Parameters:
allow_partial_search_results (bool | None) – 如果为 true,当存在分片请求超时或分片失败时,响应包含部分结果。如果为 false,API 返回错误且不包含部分结果。
catalog (str | None) – 查询的默认目录(集群)。如果未指定,查询仅在本地集群的数据上执行。
columnar (bool | None) – 如果为 true,结果以列式方式呈现:一行表示当前结果页中某列的所有值。API 仅对 CBOR、JSON、SMILE 和 YAML 响应支持此参数。
cursor (str | None) – 用于检索分页结果集的游标。如果指定游标,API 仅使用 columnar 和 time_zone 请求体参数,忽略其他请求体参数。
fetch_size (int | None) – 单次响应中返回的最大行数(或条目数)。
field_multi_value_leniency (bool | None) – 如果为 false,当遇到字段的多个值时,API 返回异常。如果为 true,API 宽松处理并返回数组中的第一个值,不保证结果一致性。
filter (Mapping[str, Any] | None) – 用于额外过滤的 Elasticsearch 查询 DSL。
format (str | Literal['cbor', 'csv', 'json', 'smile', 'tsv', 'txt', 'yaml'] | None) – 响应的格式。也可以使用 Accept HTTP 头指定格式。如果同时指定此参数和 Accept HTTP 头,此参数优先。
index_using_frozen (bool | None) – 如果为 true,搜索可以在冻结索引上运行。
keep_alive (str | Literal[-1] | ~typing.Literal[0] | None) – 异步或保存的同步搜索的保留期。
keep_on_completion (bool | None) – 如果为 true,当同时指定 wait_for_completion_timeout 参数时,Elasticsearch 存储同步搜索。如果为 false,Elasticsearch 仅存储未在 wait_for_completion_timeout 前完成的异步搜索。
page_timeout (str | Literal[-1] | ~typing.Literal[0] | None) – 滚动游标的最小保留期。超过此时限后,分页请求可能因滚动游标不再可用而失败。后续滚动请求将延长滚动游标的生命周期,延长时间为滚动请求中的 page_timeout 时长。
query (str | None) – 要运行的 SQL 查询。
request_timeout (str | Literal[-1] | ~typing.Literal[0] | None) – 请求失败前的超时时限。
runtime_mappings (Mapping[str, Mapping[str, Any]] | None) – 搜索请求的一个或多个运行时字段。这些字段优先于同名的映射字段。
time_zone (str | None) – 搜索的 ISO-8601 时区 ID。
wait_for_completion_timeout (str | Literal[-1] | ~typing.Literal[0] | None) – 等待完整结果的期限。默认为无超时,意味着请求将等待完整的搜索结果。如果搜索未在此期限内完成,搜索将变为异步。要保存同步搜索,必须指定此参数和 keep_on_completion 参数。
error_trace (bool | None)
human (bool | None)
pretty (bool | None)
- Return type:
- translate(*, query=None, error_trace=None, fetch_size=None, filter=None, filter_path=None, human=None, pretty=None, time_zone=None, body=None)
将SQL转换为Elasticsearch查询。 将SQL搜索转换为包含Query DSL的搜索API请求。 它接受与SQL搜索API相同的请求体参数,不包括
cursor
。https://www.elastic.co/docs/api/doc/elasticsearch/operation/operation-sql-translate