Skip to content

Commit

Permalink
[8.1] Serialize 'sort' parameter into query when using shorthand format
Browse files Browse the repository at this point in the history
  • Loading branch information
sethmlarson authored Feb 16, 2022
1 parent 60a5830 commit e891c09
Show file tree
Hide file tree
Showing 23 changed files with 397 additions and 52 deletions.
60 changes: 52 additions & 8 deletions elasticsearch/_async/client/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -604,7 +604,7 @@ async def bulk(
] = None,
timeout: t.Optional[t.Union[int, str]] = None,
wait_for_active_shards: t.Optional[
t.Union[int, t.Union["t.Literal['all']", str]]
t.Union[int, t.Union["t.Literal['all', 'index-setting']", str]]
] = None,
) -> ObjectApiResponse[t.Any]:
"""
Expand Down Expand Up @@ -925,7 +925,7 @@ async def create(
t.Union["t.Literal['external', 'external_gte', 'force', 'internal']", str]
] = None,
wait_for_active_shards: t.Optional[
t.Union[int, t.Union["t.Literal['all']", str]]
t.Union[int, t.Union["t.Literal['all', 'index-setting']", str]]
] = None,
) -> ObjectApiResponse[t.Any]:
"""
Expand Down Expand Up @@ -1011,7 +1011,7 @@ async def delete(
t.Union["t.Literal['external', 'external_gte', 'force', 'internal']", str]
] = None,
wait_for_active_shards: t.Optional[
t.Union[int, t.Union["t.Literal['all']", str]]
t.Union[int, t.Union["t.Literal['all', 'index-setting']", str]]
] = None,
) -> ObjectApiResponse[t.Any]:
"""
Expand Down Expand Up @@ -1136,7 +1136,7 @@ async def delete_by_query(
timeout: t.Optional[t.Union[int, str]] = None,
version: t.Optional[bool] = None,
wait_for_active_shards: t.Optional[
t.Union[int, t.Union["t.Literal['all']", str]]
t.Union[int, t.Union["t.Literal['all', 'index-setting']", str]]
] = None,
wait_for_completion: t.Optional[bool] = None,
) -> ObjectApiResponse[t.Any]:
Expand Down Expand Up @@ -1205,6 +1205,17 @@ async def delete_by_query(
__path = f"/{_quote(index)}/_delete_by_query"
__query: t.Dict[str, t.Any] = {}
__body: t.Dict[str, t.Any] = {}
# The 'sort' parameter with a colon can't be encoded to the body.
if sort is not None and (
(isinstance(sort, str) and ":" in sort)
or (
isinstance(sort, (list, tuple))
and all(isinstance(_x, str) for _x in sort)
and any(":" in _x for _x in sort)
)
):
__query["sort"] = sort
sort = None
if allow_no_indices is not None:
__query["allow_no_indices"] = allow_no_indices
if analyze_wildcard is not None:
Expand Down Expand Up @@ -2127,7 +2138,7 @@ async def index(
t.Union["t.Literal['external', 'external_gte', 'force', 'internal']", str]
] = None,
wait_for_active_shards: t.Optional[
t.Union[int, t.Union["t.Literal['all']", str]]
t.Union[int, t.Union["t.Literal['all', 'index-setting']", str]]
] = None,
) -> ObjectApiResponse[t.Any]:
"""
Expand Down Expand Up @@ -2981,7 +2992,7 @@ async def reindex(
source: t.Optional[t.Mapping[str, t.Any]] = None,
timeout: t.Optional[t.Union[int, str]] = None,
wait_for_active_shards: t.Optional[
t.Union[int, t.Union["t.Literal['all']", str]]
t.Union[int, t.Union["t.Literal['all', 'index-setting']", str]]
] = None,
wait_for_completion: t.Optional[bool] = None,
) -> ObjectApiResponse[t.Any]:
Expand Down Expand Up @@ -3540,6 +3551,17 @@ async def search(
__path = "/_search"
__body: t.Dict[str, t.Any] = {}
__query: t.Dict[str, t.Any] = {}
# The 'sort' parameter with a colon can't be encoded to the body.
if sort is not None and (
(isinstance(sort, str) and ":" in sort)
or (
isinstance(sort, (list, tuple))
and all(isinstance(_x, str) for _x in sort)
and any(":" in _x for _x in sort)
)
):
__query["sort"] = sort
sort = None
if aggregations is not None:
__body["aggregations"] = aggregations
if aggs is not None:
Expand Down Expand Up @@ -3785,6 +3807,17 @@ async def search_mvt(
__path = f"/{_quote(index)}/_mvt/{_quote(field)}/{_quote(zoom)}/{_quote(x)}/{_quote(y)}"
__body: t.Dict[str, t.Any] = {}
__query: t.Dict[str, t.Any] = {}
# The 'sort' parameter with a colon can't be encoded to the body.
if sort is not None and (
(isinstance(sort, str) and ":" in sort)
or (
isinstance(sort, (list, tuple))
and all(isinstance(_x, str) for _x in sort)
and any(":" in _x for _x in sort)
)
):
__query["sort"] = sort
sort = None
if aggs is not None:
__body["aggs"] = aggs
if error_trace is not None:
Expand Down Expand Up @@ -4289,7 +4322,7 @@ async def update(
timeout: t.Optional[t.Union[int, str]] = None,
upsert: t.Optional[t.Mapping[str, t.Any]] = None,
wait_for_active_shards: t.Optional[
t.Union[int, t.Union["t.Literal['all']", str]]
t.Union[int, t.Union["t.Literal['all', 'index-setting']", str]]
] = None,
) -> ObjectApiResponse[t.Any]:
"""
Expand Down Expand Up @@ -4454,7 +4487,7 @@ async def update_by_query(
version: t.Optional[bool] = None,
version_type: t.Optional[bool] = None,
wait_for_active_shards: t.Optional[
t.Union[int, t.Union["t.Literal['all']", str]]
t.Union[int, t.Union["t.Literal['all', 'index-setting']", str]]
] = None,
wait_for_completion: t.Optional[bool] = None,
) -> ObjectApiResponse[t.Any]:
Expand Down Expand Up @@ -4528,6 +4561,17 @@ async def update_by_query(
__path = f"/{_quote(index)}/_update_by_query"
__query: t.Dict[str, t.Any] = {}
__body: t.Dict[str, t.Any] = {}
# The 'sort' parameter with a colon can't be encoded to the body.
if sort is not None and (
(isinstance(sort, str) and ":" in sort)
or (
isinstance(sort, (list, tuple))
and all(isinstance(_x, str) for _x in sort)
and any(":" in _x for _x in sort)
)
):
__query["sort"] = sort
sort = None
if allow_no_indices is not None:
__query["allow_no_indices"] = allow_no_indices
if analyze_wildcard is not None:
Expand Down
11 changes: 11 additions & 0 deletions elasticsearch/_async/client/async_search.py
Original file line number Diff line number Diff line change
Expand Up @@ -427,6 +427,17 @@ async def submit(
__path = "/_async_search"
__body: t.Dict[str, t.Any] = {}
__query: t.Dict[str, t.Any] = {}
# The 'sort' parameter with a colon can't be encoded to the body.
if sort is not None and (
(isinstance(sort, str) and ":" in sort)
or (
isinstance(sort, (list, tuple))
and all(isinstance(_x, str) for _x in sort)
and any(":" in _x for _x in sort)
)
):
__query["sort"] = sort
sort = None
if aggregations is not None:
__body["aggregations"] = aggregations
if aggs is not None:
Expand Down
2 changes: 1 addition & 1 deletion elasticsearch/_async/client/ccr.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ async def follow(
read_poll_timeout: t.Optional[t.Union[int, str]] = None,
remote_cluster: t.Optional[str] = None,
wait_for_active_shards: t.Optional[
t.Union[int, t.Union["t.Literal['all']", str]]
t.Union[int, t.Union["t.Literal['all', 'index-setting']", str]]
] = None,
) -> ObjectApiResponse[t.Any]:
"""
Expand Down
2 changes: 1 addition & 1 deletion elasticsearch/_async/client/cluster.py
Original file line number Diff line number Diff line change
Expand Up @@ -360,7 +360,7 @@ async def health(
pretty: t.Optional[bool] = None,
timeout: t.Optional[t.Union[int, str]] = None,
wait_for_active_shards: t.Optional[
t.Union[int, t.Union["t.Literal['all']", str]]
t.Union[int, t.Union["t.Literal['all', 'index-setting']", str]]
] = None,
wait_for_events: t.Optional[
t.Union[
Expand Down
11 changes: 11 additions & 0 deletions elasticsearch/_async/client/fleet.py
Original file line number Diff line number Diff line change
Expand Up @@ -489,6 +489,17 @@ async def search(
__path = f"/{_quote(index)}/_fleet/_fleet_search"
__body: t.Dict[str, t.Any] = {}
__query: t.Dict[str, t.Any] = {}
# The 'sort' parameter with a colon can't be encoded to the body.
if sort is not None and (
(isinstance(sort, str) and ":" in sort)
or (
isinstance(sort, (list, tuple))
and all(isinstance(_x, str) for _x in sort)
and any(":" in _x for _x in sort)
)
):
__query["sort"] = sort
sort = None
if aggregations is not None:
__body["aggregations"] = aggregations
if aggs is not None:
Expand Down
36 changes: 25 additions & 11 deletions elasticsearch/_async/client/indices.py
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,7 @@ async def clone(
settings: t.Optional[t.Mapping[str, t.Any]] = None,
timeout: t.Optional[t.Union[int, str]] = None,
wait_for_active_shards: t.Optional[
t.Union[int, t.Union["t.Literal['all']", str]]
t.Union[int, t.Union["t.Literal['all', 'index-setting']", str]]
] = None,
) -> ObjectApiResponse[t.Any]:
"""
Expand Down Expand Up @@ -389,7 +389,7 @@ async def close(
pretty: t.Optional[bool] = None,
timeout: t.Optional[t.Union[int, str]] = None,
wait_for_active_shards: t.Optional[
t.Union[int, t.Union["t.Literal['all']", str]]
t.Union[int, t.Union["t.Literal['all', 'index-setting']", str]]
] = None,
) -> ObjectApiResponse[t.Any]:
"""
Expand Down Expand Up @@ -458,7 +458,7 @@ async def create(
settings: t.Optional[t.Mapping[str, t.Any]] = None,
timeout: t.Optional[t.Union[int, str]] = None,
wait_for_active_shards: t.Optional[
t.Union[int, t.Union["t.Literal['all']", str]]
t.Union[int, t.Union["t.Literal['all', 'index-setting']", str]]
] = None,
) -> ObjectApiResponse[t.Any]:
"""
Expand Down Expand Up @@ -794,20 +794,28 @@ async def delete_data_stream(
async def delete_index_template(
self,
*,
name: str,
name: t.Union[str, t.Union[t.List[str], t.Tuple[str, ...]]],
error_trace: t.Optional[bool] = None,
filter_path: t.Optional[
t.Union[str, t.Union[t.List[str], t.Tuple[str, ...]]]
] = None,
human: t.Optional[bool] = None,
master_timeout: t.Optional[t.Union[int, str]] = None,
pretty: t.Optional[bool] = None,
timeout: t.Optional[t.Union[int, str]] = None,
) -> ObjectApiResponse[t.Any]:
"""
Deletes an index template.
`<https://www.elastic.co/guide/en/elasticsearch/reference/master/indices-templates.html>`_
:param name: The name of the template
:param name: Comma-separated list of index template names used to limit the request.
Wildcard (*) expressions are supported.
:param master_timeout: Period to wait for a connection to the master node. If
no response is received before the timeout expires, the request fails and
returns an error.
:param timeout: Period to wait for a response. If no response is received before
the timeout expires, the request fails and returns an error.
"""
if name in SKIP_IN_PATH:
raise ValueError("Empty value passed for parameter 'name'")
Expand All @@ -819,8 +827,12 @@ async def delete_index_template(
__query["filter_path"] = filter_path
if human is not None:
__query["human"] = human
if master_timeout is not None:
__query["master_timeout"] = master_timeout
if pretty is not None:
__query["pretty"] = pretty
if timeout is not None:
__query["timeout"] = timeout
__headers = {"accept": "application/json"}
return await self.perform_request( # type: ignore[return-value]
"DELETE", __path, params=__query, headers=__headers
Expand Down Expand Up @@ -1236,7 +1248,7 @@ async def exists_template(
async def field_usage_stats(
self,
*,
index: t.Optional[t.Union[str, t.Union[t.List[str], t.Tuple[str, ...]]]] = None,
index: t.Union[str, t.Union[t.List[str], t.Tuple[str, ...]]],
allow_no_indices: t.Optional[bool] = None,
error_trace: t.Optional[bool] = None,
expand_wildcards: t.Optional[
Expand Down Expand Up @@ -1269,7 +1281,7 @@ async def field_usage_stats(
pretty: t.Optional[bool] = None,
timeout: t.Optional[t.Union[int, str]] = None,
wait_for_active_shards: t.Optional[
t.Union[int, t.Union["t.Literal['all']", str]]
t.Union[int, t.Union["t.Literal['all', 'index-setting']", str]]
] = None,
) -> ObjectApiResponse[t.Any]:
"""
Expand Down Expand Up @@ -1301,6 +1313,8 @@ async def field_usage_stats(
before proceeding with the operation. Set to all or any positive integer
up to the total number of shards in the index (`number_of_replicas+1`).
"""
if index in SKIP_IN_PATH:
raise ValueError("Empty value passed for parameter 'index'")
__path = f"/{_quote(index)}/_field_usage_stats"
__query: t.Dict[str, t.Any] = {}
if allow_no_indices is not None:
Expand Down Expand Up @@ -2172,7 +2186,7 @@ async def open(
pretty: t.Optional[bool] = None,
timeout: t.Optional[t.Union[int, str]] = None,
wait_for_active_shards: t.Optional[
t.Union[int, t.Union["t.Literal['all']", str]]
t.Union[int, t.Union["t.Literal['all', 'index-setting']", str]]
] = None,
) -> ObjectApiResponse[t.Any]:
"""
Expand Down Expand Up @@ -3025,7 +3039,7 @@ async def rollover(
settings: t.Optional[t.Mapping[str, t.Any]] = None,
timeout: t.Optional[t.Union[int, str]] = None,
wait_for_active_shards: t.Optional[
t.Union[int, t.Union["t.Literal['all']", str]]
t.Union[int, t.Union["t.Literal['all', 'index-setting']", str]]
] = None,
) -> ObjectApiResponse[t.Any]:
"""
Expand Down Expand Up @@ -3269,7 +3283,7 @@ async def shrink(
settings: t.Optional[t.Mapping[str, t.Any]] = None,
timeout: t.Optional[t.Union[int, str]] = None,
wait_for_active_shards: t.Optional[
t.Union[int, t.Union["t.Literal['all']", str]]
t.Union[int, t.Union["t.Literal['all', 'index-setting']", str]]
] = None,
) -> ObjectApiResponse[t.Any]:
"""
Expand Down Expand Up @@ -3491,7 +3505,7 @@ async def split(
settings: t.Optional[t.Mapping[str, t.Any]] = None,
timeout: t.Optional[t.Union[int, str]] = None,
wait_for_active_shards: t.Optional[
t.Union[int, t.Union["t.Literal['all']", str]]
t.Union[int, t.Union["t.Literal['all', 'index-setting']", str]]
] = None,
) -> ObjectApiResponse[t.Any]:
"""
Expand Down
10 changes: 7 additions & 3 deletions elasticsearch/_async/client/ml.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ async def delete_calendar_job(
self,
*,
calendar_id: str,
job_id: str,
job_id: t.Union[str, t.Union[t.List[str], t.Tuple[str, ...]]],
error_trace: t.Optional[bool] = None,
filter_path: t.Optional[
t.Union[str, t.Union[t.List[str], t.Tuple[str, ...]]]
Expand Down Expand Up @@ -1464,7 +1464,9 @@ async def get_datafeeds(
async def get_filters(
self,
*,
filter_id: t.Optional[str] = None,
filter_id: t.Optional[
t.Union[str, t.Union[t.List[str], t.Tuple[str, ...]]]
] = None,
error_trace: t.Optional[bool] = None,
filter_path: t.Optional[
t.Union[str, t.Union[t.List[str], t.Tuple[str, ...]]]
Expand Down Expand Up @@ -2028,7 +2030,9 @@ async def get_trained_models(
async def get_trained_models_stats(
self,
*,
model_id: t.Optional[str] = None,
model_id: t.Optional[
t.Union[str, t.Union[t.List[str], t.Tuple[str, ...]]]
] = None,
allow_no_match: t.Optional[bool] = None,
error_trace: t.Optional[bool] = None,
filter_path: t.Optional[
Expand Down
11 changes: 11 additions & 0 deletions elasticsearch/_async/client/security.py
Original file line number Diff line number Diff line change
Expand Up @@ -1848,6 +1848,17 @@ async def query_api_keys(
__path = "/_security/_query/api_key"
__query: t.Dict[str, t.Any] = {}
__body: t.Dict[str, t.Any] = {}
# The 'sort' parameter with a colon can't be encoded to the body.
if sort is not None and (
(isinstance(sort, str) and ":" in sort)
or (
isinstance(sort, (list, tuple))
and all(isinstance(_x, str) for _x in sort)
and any(":" in _x for _x in sort)
)
):
__query["sort"] = sort
sort = None
if error_trace is not None:
__query["error_trace"] = error_trace
if filter_path is not None:
Expand Down
Loading

0 comments on commit e891c09

Please sign in to comment.