20
20
from elastic_transport import ObjectApiResponse
21
21
22
22
from ._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
+ )
24
30
25
31
26
32
class EsqlClient (NamespacedClient ):
@@ -31,6 +37,8 @@ class EsqlClient(NamespacedClient):
31
37
"columnar" ,
32
38
"filter" ,
33
39
"include_ccs_metadata" ,
40
+ "keep_alive" ,
41
+ "keep_on_completion" ,
34
42
"locale" ,
35
43
"params" ,
36
44
"profile" ,
@@ -88,7 +96,9 @@ async def async_query(
88
96
parameter, runs it, and returns the results.
89
97
:param allow_partial_results: If `true`, partial results will be returned if
90
98
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`.
92
102
:param columnar: By default, ES|QL returns results as rows. For example, FROM
93
103
returns each individual document as one row. For the JSON, YAML, CBOR and
94
104
smile formats, ES|QL can return the results in a columnar fashion where one
@@ -151,10 +161,6 @@ async def async_query(
151
161
__query ["format" ] = format
152
162
if human is not None :
153
163
__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
158
164
if pretty is not None :
159
165
__query ["pretty" ] = pretty
160
166
if not __body :
@@ -166,6 +172,10 @@ async def async_query(
166
172
__body ["filter" ] = filter
167
173
if include_ccs_metadata is not None :
168
174
__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
169
179
if locale is not None :
170
180
__body ["locale" ] = locale
171
181
if params is not None :
@@ -248,6 +258,14 @@ async def async_query_get(
248
258
drop_null_columns : t .Optional [bool ] = None ,
249
259
error_trace : t .Optional [bool ] = None ,
250
260
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 ,
251
269
human : t .Optional [bool ] = None ,
252
270
keep_alive : t .Optional [t .Union [str , t .Literal [- 1 ], t .Literal [0 ]]] = None ,
253
271
pretty : t .Optional [bool ] = None ,
@@ -273,6 +291,7 @@ async def async_query_get(
273
291
will be removed from the `columns` and `values` portion of the results. If
274
292
`true`, the response will include an extra section under the name `all_columns`
275
293
which has the name of all the columns.
294
+ :param format: A short version of the Accept header, for example `json` or `yaml`.
276
295
:param keep_alive: The period for which the query and its results are stored
277
296
in the cluster. When this period expires, the query and its results are deleted,
278
297
even if the query is still ongoing.
@@ -293,6 +312,8 @@ async def async_query_get(
293
312
__query ["error_trace" ] = error_trace
294
313
if filter_path is not None :
295
314
__query ["filter_path" ] = filter_path
315
+ if format is not None :
316
+ __query ["format" ] = format
296
317
if human is not None :
297
318
__query ["human" ] = human
298
319
if keep_alive is not None :
@@ -366,6 +387,87 @@ async def async_query_stop(
366
387
path_parts = __path_parts ,
367
388
)
368
389
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
+
369
471
@_rewrite_parameters (
370
472
body_fields = (
371
473
"query" ,
@@ -422,7 +524,9 @@ async def query(
422
524
parameter, runs it, and returns the results.
423
525
:param allow_partial_results: If `true`, partial results will be returned if
424
526
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`.
426
530
:param columnar: By default, ES|QL returns results as rows. For example, FROM
427
531
returns each individual document as one row. For the JSON, YAML, CBOR and
428
532
smile formats, ES|QL can return the results in a columnar fashion where one
0 commit comments