2020from elastic_transport import ObjectApiResponse
2121
2222from ._base import NamespacedClient
23- from .utils import SKIP_IN_PATH , _quote , _rewrite_parameters
23+ from .utils import (
24+ SKIP_IN_PATH ,
25+ Stability ,
26+ _quote ,
27+ _rewrite_parameters ,
28+ _stability_warning ,
29+ )
2430
2531
2632class EsqlClient (NamespacedClient ):
@@ -31,6 +37,8 @@ class EsqlClient(NamespacedClient):
3137 "columnar" ,
3238 "filter" ,
3339 "include_ccs_metadata" ,
40+ "keep_alive" ,
41+ "keep_on_completion" ,
3442 "locale" ,
3543 "params" ,
3644 "profile" ,
@@ -88,7 +96,9 @@ async def async_query(
8896 parameter, runs it, and returns the results.
8997 :param allow_partial_results: If `true`, partial results will be returned if
9098 there are shard failures, but the query can continue to execute on other
91- clusters and shards.
99+ clusters and shards. If `false`, the query will fail if there are any failures.
100+ To override the default behavior, you can set the `esql.query.allow_partial_results`
101+ cluster setting to `false`.
92102 :param columnar: By default, ES|QL returns results as rows. For example, FROM
93103 returns each individual document as one row. For the JSON, YAML, CBOR and
94104 smile formats, ES|QL can return the results in a columnar fashion where one
@@ -151,10 +161,6 @@ async def async_query(
151161 __query ["format" ] = format
152162 if human is not None :
153163 __query ["human" ] = human
154- if keep_alive is not None :
155- __query ["keep_alive" ] = keep_alive
156- if keep_on_completion is not None :
157- __query ["keep_on_completion" ] = keep_on_completion
158164 if pretty is not None :
159165 __query ["pretty" ] = pretty
160166 if not __body :
@@ -166,6 +172,10 @@ async def async_query(
166172 __body ["filter" ] = filter
167173 if include_ccs_metadata is not None :
168174 __body ["include_ccs_metadata" ] = include_ccs_metadata
175+ if keep_alive is not None :
176+ __body ["keep_alive" ] = keep_alive
177+ if keep_on_completion is not None :
178+ __body ["keep_on_completion" ] = keep_on_completion
169179 if locale is not None :
170180 __body ["locale" ] = locale
171181 if params is not None :
@@ -248,6 +258,14 @@ async def async_query_get(
248258 drop_null_columns : t .Optional [bool ] = None ,
249259 error_trace : t .Optional [bool ] = None ,
250260 filter_path : t .Optional [t .Union [str , t .Sequence [str ]]] = None ,
261+ format : t .Optional [
262+ t .Union [
263+ str ,
264+ t .Literal [
265+ "arrow" , "cbor" , "csv" , "json" , "smile" , "tsv" , "txt" , "yaml"
266+ ],
267+ ]
268+ ] = None ,
251269 human : t .Optional [bool ] = None ,
252270 keep_alive : t .Optional [t .Union [str , t .Literal [- 1 ], t .Literal [0 ]]] = None ,
253271 pretty : t .Optional [bool ] = None ,
@@ -273,6 +291,7 @@ async def async_query_get(
273291 will be removed from the `columns` and `values` portion of the results. If
274292 `true`, the response will include an extra section under the name `all_columns`
275293 which has the name of all the columns.
294+ :param format: A short version of the Accept header, for example `json` or `yaml`.
276295 :param keep_alive: The period for which the query and its results are stored
277296 in the cluster. When this period expires, the query and its results are deleted,
278297 even if the query is still ongoing.
@@ -293,6 +312,8 @@ async def async_query_get(
293312 __query ["error_trace" ] = error_trace
294313 if filter_path is not None :
295314 __query ["filter_path" ] = filter_path
315+ if format is not None :
316+ __query ["format" ] = format
296317 if human is not None :
297318 __query ["human" ] = human
298319 if keep_alive is not None :
@@ -366,6 +387,87 @@ async def async_query_stop(
366387 path_parts = __path_parts ,
367388 )
368389
390+ @_rewrite_parameters ()
391+ @_stability_warning (Stability .EXPERIMENTAL )
392+ async def get_query (
393+ self ,
394+ * ,
395+ id : str ,
396+ error_trace : t .Optional [bool ] = None ,
397+ filter_path : t .Optional [t .Union [str , t .Sequence [str ]]] = None ,
398+ human : t .Optional [bool ] = None ,
399+ pretty : t .Optional [bool ] = None ,
400+ ) -> ObjectApiResponse [t .Any ]:
401+ """
402+ .. raw:: html
403+
404+ <p>Get a specific running ES|QL query information.
405+ Returns an object extended information about a running ES|QL query.</p>
406+
407+
408+ :param id: The query ID
409+ """
410+ if id in SKIP_IN_PATH :
411+ raise ValueError ("Empty value passed for parameter 'id'" )
412+ __path_parts : t .Dict [str , str ] = {"id" : _quote (id )}
413+ __path = f'/_query/queries/{ __path_parts ["id" ]} '
414+ __query : t .Dict [str , t .Any ] = {}
415+ if error_trace is not None :
416+ __query ["error_trace" ] = error_trace
417+ if filter_path is not None :
418+ __query ["filter_path" ] = filter_path
419+ if human is not None :
420+ __query ["human" ] = human
421+ if pretty is not None :
422+ __query ["pretty" ] = pretty
423+ __headers = {"accept" : "application/json" }
424+ return await self .perform_request ( # type: ignore[return-value]
425+ "GET" ,
426+ __path ,
427+ params = __query ,
428+ headers = __headers ,
429+ endpoint_id = "esql.get_query" ,
430+ path_parts = __path_parts ,
431+ )
432+
433+ @_rewrite_parameters ()
434+ @_stability_warning (Stability .EXPERIMENTAL )
435+ async def list_queries (
436+ self ,
437+ * ,
438+ error_trace : t .Optional [bool ] = None ,
439+ filter_path : t .Optional [t .Union [str , t .Sequence [str ]]] = None ,
440+ human : t .Optional [bool ] = None ,
441+ pretty : t .Optional [bool ] = None ,
442+ ) -> ObjectApiResponse [t .Any ]:
443+ """
444+ .. raw:: html
445+
446+ <p>Get running ES|QL queries information.
447+ Returns an object containing IDs and other information about the running ES|QL queries.</p>
448+
449+ """
450+ __path_parts : t .Dict [str , str ] = {}
451+ __path = "/_query/queries"
452+ __query : t .Dict [str , t .Any ] = {}
453+ if error_trace is not None :
454+ __query ["error_trace" ] = error_trace
455+ if filter_path is not None :
456+ __query ["filter_path" ] = filter_path
457+ if human is not None :
458+ __query ["human" ] = human
459+ if pretty is not None :
460+ __query ["pretty" ] = pretty
461+ __headers = {"accept" : "application/json" }
462+ return await self .perform_request ( # type: ignore[return-value]
463+ "GET" ,
464+ __path ,
465+ params = __query ,
466+ headers = __headers ,
467+ endpoint_id = "esql.list_queries" ,
468+ path_parts = __path_parts ,
469+ )
470+
369471 @_rewrite_parameters (
370472 body_fields = (
371473 "query" ,
@@ -422,7 +524,9 @@ async def query(
422524 parameter, runs it, and returns the results.
423525 :param allow_partial_results: If `true`, partial results will be returned if
424526 there are shard failures, but the query can continue to execute on other
425- clusters and shards.
527+ clusters and shards. If `false`, the query will fail if there are any failures.
528+ To override the default behavior, you can set the `esql.query.allow_partial_results`
529+ cluster setting to `false`.
426530 :param columnar: By default, ES|QL returns results as rows. For example, FROM
427531 returns each individual document as one row. For the JSON, YAML, CBOR and
428532 smile formats, ES|QL can return the results in a columnar fashion where one
0 commit comments