Skip to content

Commit 74aa9de

Browse files
authored
[8.0] Serialize 'sort' parameter into query when using shorthand format
1 parent 3c788d2 commit 74aa9de

23 files changed

+391
-50
lines changed

elasticsearch/_async/client/__init__.py

+52-8
Original file line numberDiff line numberDiff line change
@@ -604,7 +604,7 @@ async def bulk(
604604
] = None,
605605
timeout: t.Optional[t.Union[int, str]] = None,
606606
wait_for_active_shards: t.Optional[
607-
t.Union[int, t.Union["t.Literal['all']", str]]
607+
t.Union[int, t.Union["t.Literal['all', 'index-setting']", str]]
608608
] = None,
609609
) -> ObjectApiResponse[t.Any]:
610610
"""
@@ -925,7 +925,7 @@ async def create(
925925
t.Union["t.Literal['external', 'external_gte', 'force', 'internal']", str]
926926
] = None,
927927
wait_for_active_shards: t.Optional[
928-
t.Union[int, t.Union["t.Literal['all']", str]]
928+
t.Union[int, t.Union["t.Literal['all', 'index-setting']", str]]
929929
] = None,
930930
) -> ObjectApiResponse[t.Any]:
931931
"""
@@ -1011,7 +1011,7 @@ async def delete(
10111011
t.Union["t.Literal['external', 'external_gte', 'force', 'internal']", str]
10121012
] = None,
10131013
wait_for_active_shards: t.Optional[
1014-
t.Union[int, t.Union["t.Literal['all']", str]]
1014+
t.Union[int, t.Union["t.Literal['all', 'index-setting']", str]]
10151015
] = None,
10161016
) -> ObjectApiResponse[t.Any]:
10171017
"""
@@ -1136,7 +1136,7 @@ async def delete_by_query(
11361136
timeout: t.Optional[t.Union[int, str]] = None,
11371137
version: t.Optional[bool] = None,
11381138
wait_for_active_shards: t.Optional[
1139-
t.Union[int, t.Union["t.Literal['all']", str]]
1139+
t.Union[int, t.Union["t.Literal['all', 'index-setting']", str]]
11401140
] = None,
11411141
wait_for_completion: t.Optional[bool] = None,
11421142
) -> ObjectApiResponse[t.Any]:
@@ -1205,6 +1205,17 @@ async def delete_by_query(
12051205
__path = f"/{_quote(index)}/_delete_by_query"
12061206
__query: t.Dict[str, t.Any] = {}
12071207
__body: t.Dict[str, t.Any] = {}
1208+
# The 'sort' parameter with a colon can't be encoded to the body.
1209+
if sort is not None and (
1210+
(isinstance(sort, str) and ":" in sort)
1211+
or (
1212+
isinstance(sort, (list, tuple))
1213+
and all(isinstance(_x, str) for _x in sort)
1214+
and any(":" in _x for _x in sort)
1215+
)
1216+
):
1217+
__query["sort"] = sort
1218+
sort = None
12081219
if allow_no_indices is not None:
12091220
__query["allow_no_indices"] = allow_no_indices
12101221
if analyze_wildcard is not None:
@@ -2127,7 +2138,7 @@ async def index(
21272138
t.Union["t.Literal['external', 'external_gte', 'force', 'internal']", str]
21282139
] = None,
21292140
wait_for_active_shards: t.Optional[
2130-
t.Union[int, t.Union["t.Literal['all']", str]]
2141+
t.Union[int, t.Union["t.Literal['all', 'index-setting']", str]]
21312142
] = None,
21322143
) -> ObjectApiResponse[t.Any]:
21332144
"""
@@ -2981,7 +2992,7 @@ async def reindex(
29812992
source: t.Optional[t.Mapping[str, t.Any]] = None,
29822993
timeout: t.Optional[t.Union[int, str]] = None,
29832994
wait_for_active_shards: t.Optional[
2984-
t.Union[int, t.Union["t.Literal['all']", str]]
2995+
t.Union[int, t.Union["t.Literal['all', 'index-setting']", str]]
29852996
] = None,
29862997
wait_for_completion: t.Optional[bool] = None,
29872998
) -> ObjectApiResponse[t.Any]:
@@ -3540,6 +3551,17 @@ async def search(
35403551
__path = "/_search"
35413552
__body: t.Dict[str, t.Any] = {}
35423553
__query: t.Dict[str, t.Any] = {}
3554+
# The 'sort' parameter with a colon can't be encoded to the body.
3555+
if sort is not None and (
3556+
(isinstance(sort, str) and ":" in sort)
3557+
or (
3558+
isinstance(sort, (list, tuple))
3559+
and all(isinstance(_x, str) for _x in sort)
3560+
and any(":" in _x for _x in sort)
3561+
)
3562+
):
3563+
__query["sort"] = sort
3564+
sort = None
35433565
if aggregations is not None:
35443566
__body["aggregations"] = aggregations
35453567
if aggs is not None:
@@ -3785,6 +3807,17 @@ async def search_mvt(
37853807
__path = f"/{_quote(index)}/_mvt/{_quote(field)}/{_quote(zoom)}/{_quote(x)}/{_quote(y)}"
37863808
__body: t.Dict[str, t.Any] = {}
37873809
__query: t.Dict[str, t.Any] = {}
3810+
# The 'sort' parameter with a colon can't be encoded to the body.
3811+
if sort is not None and (
3812+
(isinstance(sort, str) and ":" in sort)
3813+
or (
3814+
isinstance(sort, (list, tuple))
3815+
and all(isinstance(_x, str) for _x in sort)
3816+
and any(":" in _x for _x in sort)
3817+
)
3818+
):
3819+
__query["sort"] = sort
3820+
sort = None
37883821
if aggs is not None:
37893822
__body["aggs"] = aggs
37903823
if error_trace is not None:
@@ -4289,7 +4322,7 @@ async def update(
42894322
timeout: t.Optional[t.Union[int, str]] = None,
42904323
upsert: t.Optional[t.Mapping[str, t.Any]] = None,
42914324
wait_for_active_shards: t.Optional[
4292-
t.Union[int, t.Union["t.Literal['all']", str]]
4325+
t.Union[int, t.Union["t.Literal['all', 'index-setting']", str]]
42934326
] = None,
42944327
) -> ObjectApiResponse[t.Any]:
42954328
"""
@@ -4454,7 +4487,7 @@ async def update_by_query(
44544487
version: t.Optional[bool] = None,
44554488
version_type: t.Optional[bool] = None,
44564489
wait_for_active_shards: t.Optional[
4457-
t.Union[int, t.Union["t.Literal['all']", str]]
4490+
t.Union[int, t.Union["t.Literal['all', 'index-setting']", str]]
44584491
] = None,
44594492
wait_for_completion: t.Optional[bool] = None,
44604493
) -> ObjectApiResponse[t.Any]:
@@ -4528,6 +4561,17 @@ async def update_by_query(
45284561
__path = f"/{_quote(index)}/_update_by_query"
45294562
__query: t.Dict[str, t.Any] = {}
45304563
__body: t.Dict[str, t.Any] = {}
4564+
# The 'sort' parameter with a colon can't be encoded to the body.
4565+
if sort is not None and (
4566+
(isinstance(sort, str) and ":" in sort)
4567+
or (
4568+
isinstance(sort, (list, tuple))
4569+
and all(isinstance(_x, str) for _x in sort)
4570+
and any(":" in _x for _x in sort)
4571+
)
4572+
):
4573+
__query["sort"] = sort
4574+
sort = None
45314575
if allow_no_indices is not None:
45324576
__query["allow_no_indices"] = allow_no_indices
45334577
if analyze_wildcard is not None:

elasticsearch/_async/client/async_search.py

+11
Original file line numberDiff line numberDiff line change
@@ -427,6 +427,17 @@ async def submit(
427427
__path = "/_async_search"
428428
__body: t.Dict[str, t.Any] = {}
429429
__query: t.Dict[str, t.Any] = {}
430+
# The 'sort' parameter with a colon can't be encoded to the body.
431+
if sort is not None and (
432+
(isinstance(sort, str) and ":" in sort)
433+
or (
434+
isinstance(sort, (list, tuple))
435+
and all(isinstance(_x, str) for _x in sort)
436+
and any(":" in _x for _x in sort)
437+
)
438+
):
439+
__query["sort"] = sort
440+
sort = None
430441
if aggregations is not None:
431442
__body["aggregations"] = aggregations
432443
if aggs is not None:

elasticsearch/_async/client/ccr.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ async def follow(
8686
read_poll_timeout: t.Optional[t.Union[int, str]] = None,
8787
remote_cluster: t.Optional[str] = None,
8888
wait_for_active_shards: t.Optional[
89-
t.Union[int, t.Union["t.Literal['all']", str]]
89+
t.Union[int, t.Union["t.Literal['all', 'index-setting']", str]]
9090
] = None,
9191
) -> ObjectApiResponse[t.Any]:
9292
"""

elasticsearch/_async/client/cluster.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -360,7 +360,7 @@ async def health(
360360
pretty: t.Optional[bool] = None,
361361
timeout: t.Optional[t.Union[int, str]] = None,
362362
wait_for_active_shards: t.Optional[
363-
t.Union[int, t.Union["t.Literal['all']", str]]
363+
t.Union[int, t.Union["t.Literal['all', 'index-setting']", str]]
364364
] = None,
365365
wait_for_events: t.Optional[
366366
t.Union[

elasticsearch/_async/client/fleet.py

+11
Original file line numberDiff line numberDiff line change
@@ -489,6 +489,17 @@ async def search(
489489
__path = f"/{_quote(index)}/_fleet/_fleet_search"
490490
__body: t.Dict[str, t.Any] = {}
491491
__query: t.Dict[str, t.Any] = {}
492+
# The 'sort' parameter with a colon can't be encoded to the body.
493+
if sort is not None and (
494+
(isinstance(sort, str) and ":" in sort)
495+
or (
496+
isinstance(sort, (list, tuple))
497+
and all(isinstance(_x, str) for _x in sort)
498+
and any(":" in _x for _x in sort)
499+
)
500+
):
501+
__query["sort"] = sort
502+
sort = None
492503
if aggregations is not None:
493504
__body["aggregations"] = aggregations
494505
if aggs is not None:

elasticsearch/_async/client/indices.py

+25-11
Original file line numberDiff line numberDiff line change
@@ -304,7 +304,7 @@ async def clone(
304304
settings: t.Optional[t.Mapping[str, t.Any]] = None,
305305
timeout: t.Optional[t.Union[int, str]] = None,
306306
wait_for_active_shards: t.Optional[
307-
t.Union[int, t.Union["t.Literal['all']", str]]
307+
t.Union[int, t.Union["t.Literal['all', 'index-setting']", str]]
308308
] = None,
309309
) -> ObjectApiResponse[t.Any]:
310310
"""
@@ -389,7 +389,7 @@ async def close(
389389
pretty: t.Optional[bool] = None,
390390
timeout: t.Optional[t.Union[int, str]] = None,
391391
wait_for_active_shards: t.Optional[
392-
t.Union[int, t.Union["t.Literal['all']", str]]
392+
t.Union[int, t.Union["t.Literal['all', 'index-setting']", str]]
393393
] = None,
394394
) -> ObjectApiResponse[t.Any]:
395395
"""
@@ -458,7 +458,7 @@ async def create(
458458
settings: t.Optional[t.Mapping[str, t.Any]] = None,
459459
timeout: t.Optional[t.Union[int, str]] = None,
460460
wait_for_active_shards: t.Optional[
461-
t.Union[int, t.Union["t.Literal['all']", str]]
461+
t.Union[int, t.Union["t.Literal['all', 'index-setting']", str]]
462462
] = None,
463463
) -> ObjectApiResponse[t.Any]:
464464
"""
@@ -794,20 +794,28 @@ async def delete_data_stream(
794794
async def delete_index_template(
795795
self,
796796
*,
797-
name: str,
797+
name: t.Union[str, t.Union[t.List[str], t.Tuple[str, ...]]],
798798
error_trace: t.Optional[bool] = None,
799799
filter_path: t.Optional[
800800
t.Union[str, t.Union[t.List[str], t.Tuple[str, ...]]]
801801
] = None,
802802
human: t.Optional[bool] = None,
803+
master_timeout: t.Optional[t.Union[int, str]] = None,
803804
pretty: t.Optional[bool] = None,
805+
timeout: t.Optional[t.Union[int, str]] = None,
804806
) -> ObjectApiResponse[t.Any]:
805807
"""
806808
Deletes an index template.
807809
808810
`<https://www.elastic.co/guide/en/elasticsearch/reference/master/indices-templates.html>`_
809811
810-
:param name: The name of the template
812+
:param name: Comma-separated list of index template names used to limit the request.
813+
Wildcard (*) expressions are supported.
814+
:param master_timeout: Period to wait for a connection to the master node. If
815+
no response is received before the timeout expires, the request fails and
816+
returns an error.
817+
:param timeout: Period to wait for a response. If no response is received before
818+
the timeout expires, the request fails and returns an error.
811819
"""
812820
if name in SKIP_IN_PATH:
813821
raise ValueError("Empty value passed for parameter 'name'")
@@ -819,8 +827,12 @@ async def delete_index_template(
819827
__query["filter_path"] = filter_path
820828
if human is not None:
821829
__query["human"] = human
830+
if master_timeout is not None:
831+
__query["master_timeout"] = master_timeout
822832
if pretty is not None:
823833
__query["pretty"] = pretty
834+
if timeout is not None:
835+
__query["timeout"] = timeout
824836
__headers = {"accept": "application/json"}
825837
return await self.perform_request( # type: ignore[return-value]
826838
"DELETE", __path, params=__query, headers=__headers
@@ -1236,7 +1248,7 @@ async def exists_template(
12361248
async def field_usage_stats(
12371249
self,
12381250
*,
1239-
index: t.Optional[t.Union[str, t.Union[t.List[str], t.Tuple[str, ...]]]] = None,
1251+
index: t.Union[str, t.Union[t.List[str], t.Tuple[str, ...]]],
12401252
allow_no_indices: t.Optional[bool] = None,
12411253
error_trace: t.Optional[bool] = None,
12421254
expand_wildcards: t.Optional[
@@ -1269,7 +1281,7 @@ async def field_usage_stats(
12691281
pretty: t.Optional[bool] = None,
12701282
timeout: t.Optional[t.Union[int, str]] = None,
12711283
wait_for_active_shards: t.Optional[
1272-
t.Union[int, t.Union["t.Literal['all']", str]]
1284+
t.Union[int, t.Union["t.Literal['all', 'index-setting']", str]]
12731285
] = None,
12741286
) -> ObjectApiResponse[t.Any]:
12751287
"""
@@ -1301,6 +1313,8 @@ async def field_usage_stats(
13011313
before proceeding with the operation. Set to all or any positive integer
13021314
up to the total number of shards in the index (`number_of_replicas+1`).
13031315
"""
1316+
if index in SKIP_IN_PATH:
1317+
raise ValueError("Empty value passed for parameter 'index'")
13041318
__path = f"/{_quote(index)}/_field_usage_stats"
13051319
__query: t.Dict[str, t.Any] = {}
13061320
if allow_no_indices is not None:
@@ -2171,7 +2185,7 @@ async def open(
21712185
pretty: t.Optional[bool] = None,
21722186
timeout: t.Optional[t.Union[int, str]] = None,
21732187
wait_for_active_shards: t.Optional[
2174-
t.Union[int, t.Union["t.Literal['all']", str]]
2188+
t.Union[int, t.Union["t.Literal['all', 'index-setting']", str]]
21752189
] = None,
21762190
) -> ObjectApiResponse[t.Any]:
21772191
"""
@@ -3024,7 +3038,7 @@ async def rollover(
30243038
settings: t.Optional[t.Mapping[str, t.Any]] = None,
30253039
timeout: t.Optional[t.Union[int, str]] = None,
30263040
wait_for_active_shards: t.Optional[
3027-
t.Union[int, t.Union["t.Literal['all']", str]]
3041+
t.Union[int, t.Union["t.Literal['all', 'index-setting']", str]]
30283042
] = None,
30293043
) -> ObjectApiResponse[t.Any]:
30303044
"""
@@ -3268,7 +3282,7 @@ async def shrink(
32683282
settings: t.Optional[t.Mapping[str, t.Any]] = None,
32693283
timeout: t.Optional[t.Union[int, str]] = None,
32703284
wait_for_active_shards: t.Optional[
3271-
t.Union[int, t.Union["t.Literal['all']", str]]
3285+
t.Union[int, t.Union["t.Literal['all', 'index-setting']", str]]
32723286
] = None,
32733287
) -> ObjectApiResponse[t.Any]:
32743288
"""
@@ -3490,7 +3504,7 @@ async def split(
34903504
settings: t.Optional[t.Mapping[str, t.Any]] = None,
34913505
timeout: t.Optional[t.Union[int, str]] = None,
34923506
wait_for_active_shards: t.Optional[
3493-
t.Union[int, t.Union["t.Literal['all']", str]]
3507+
t.Union[int, t.Union["t.Literal['all', 'index-setting']", str]]
34943508
] = None,
34953509
) -> ObjectApiResponse[t.Any]:
34963510
"""

elasticsearch/_async/client/ml.py

+4-2
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ async def delete_calendar_job(
166166
self,
167167
*,
168168
calendar_id: str,
169-
job_id: str,
169+
job_id: t.Union[str, t.Union[t.List[str], t.Tuple[str, ...]]],
170170
error_trace: t.Optional[bool] = None,
171171
filter_path: t.Optional[
172172
t.Union[str, t.Union[t.List[str], t.Tuple[str, ...]]]
@@ -1464,7 +1464,9 @@ async def get_datafeeds(
14641464
async def get_filters(
14651465
self,
14661466
*,
1467-
filter_id: t.Optional[str] = None,
1467+
filter_id: t.Optional[
1468+
t.Union[str, t.Union[t.List[str], t.Tuple[str, ...]]]
1469+
] = None,
14681470
error_trace: t.Optional[bool] = None,
14691471
filter_path: t.Optional[
14701472
t.Union[str, t.Union[t.List[str], t.Tuple[str, ...]]]

elasticsearch/_async/client/security.py

+11
Original file line numberDiff line numberDiff line change
@@ -1848,6 +1848,17 @@ async def query_api_keys(
18481848
__path = "/_security/_query/api_key"
18491849
__query: t.Dict[str, t.Any] = {}
18501850
__body: t.Dict[str, t.Any] = {}
1851+
# The 'sort' parameter with a colon can't be encoded to the body.
1852+
if sort is not None and (
1853+
(isinstance(sort, str) and ":" in sort)
1854+
or (
1855+
isinstance(sort, (list, tuple))
1856+
and all(isinstance(_x, str) for _x in sort)
1857+
and any(":" in _x for _x in sort)
1858+
)
1859+
):
1860+
__query["sort"] = sort
1861+
sort = None
18511862
if error_trace is not None:
18521863
__query["error_trace"] = error_trace
18531864
if filter_path is not None:

0 commit comments

Comments
 (0)