Skip to content

Commit 5f97af0

Browse files
committed
Fixes for REST API tests
1 parent cd24521 commit 5f97af0

File tree

6 files changed

+69
-71
lines changed

6 files changed

+69
-71
lines changed

elasticsearch/_async/client/__init__.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,14 +34,15 @@
3434
from elastic_transport import (
3535
AsyncTransport,
3636
BaseNode,
37+
HeadApiResponse,
3738
NodeConfig,
3839
NodePool,
3940
NodeSelector,
4041
Serializer,
41-
TransportError,
4242
)
4343
from elastic_transport.client_utils import DEFAULT, DefaultType
4444

45+
from ...exceptions import ApiError
4546
from ...serializer import DEFAULT_SERIALIZERS
4647
from ._base import (
4748
BaseClient,
@@ -456,7 +457,7 @@ async def ping(
456457
filter_path: Optional[Union[List[str], str]] = None,
457458
human: Optional[bool] = None,
458459
pretty: Optional[bool] = None,
459-
) -> bool:
460+
) -> Any:
460461
"""
461462
Returns basic information about the cluster.
462463
@@ -479,9 +480,9 @@ async def ping(
479480
__headers = {"accept": "application/json"}
480481
try:
481482
resp = await self._perform_request("HEAD", __target, headers=__headers)
482-
return bool(resp)
483-
except TransportError:
484-
return False
483+
return resp
484+
except ApiError as e:
485+
return HeadApiResponse(meta=e.meta)
485486

486487
# AUTO-GENERATED-API-DEFINITIONS #
487488

@@ -2089,7 +2090,6 @@ async def info(
20892090
@_rewrite_parameters(
20902091
body_fields=True,
20912092
parameter_aliases={"_source": "source"},
2092-
ignore_deprecated_options=True,
20932093
)
20942094
async def knn_search(
20952095
self,

elasticsearch/_async/client/ml.py

Lines changed: 22 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -960,6 +960,7 @@ async def get_buckets(
960960
filter_path: Optional[Union[List[str], str]] = None,
961961
from_: Optional[int] = None,
962962
human: Optional[bool] = None,
963+
page: Optional[Any] = None,
963964
pretty: Optional[bool] = None,
964965
size: Optional[int] = None,
965966
sort: Optional[Any] = None,
@@ -973,18 +974,18 @@ async def get_buckets(
973974
:param job_id: Identifier for the anomaly detection job.
974975
:param timestamp: The timestamp of a single bucket result. If you do not specify
975976
this parameter, the API returns information about all buckets.
976-
:param anomaly_score: Returns buckets with anomaly scores greater or equal than
977-
this value.
978-
:param desc: If `true`, the buckets are sorted in descending order.
979-
:param end: Returns buckets with timestamps earlier than this time. `-1` means
980-
it is unset and results are not limited to specific timestamps.
981-
:param exclude_interim: If `true`, the output excludes interim results.
982-
:param expand: If true, the output includes anomaly records.
977+
:param anomaly_score: Refer to the description for the `anomaly_score` query
978+
parameter.
979+
:param desc: Refer to the description for the `desc` query parameter.
980+
:param end: Refer to the description for the `end` query parameter.
981+
:param exclude_interim: Refer to the description for the `exclude_interim` query
982+
parameter.
983+
:param expand: Refer to the description for the `expand` query parameter.
983984
:param from_: Skips the specified number of buckets.
985+
:param page:
984986
:param size: Specifies the maximum number of buckets to obtain.
985-
:param sort: Specifies the sort field for the requested buckets.
986-
:param start: Returns buckets with timestamps after this time. `-1` means it
987-
is unset and results are not limited to specific timestamps.
987+
:param sort: Refer to the desription for the `sort` query parameter.
988+
:param start: Refer to the description for the `start` query parameter.
988989
"""
989990
if job_id in SKIP_IN_PATH:
990991
raise ValueError("Empty value passed for parameter 'job_id'")
@@ -1014,6 +1015,8 @@ async def get_buckets(
10141015
__query["from"] = from_
10151016
if human is not None:
10161017
__query["human"] = human
1018+
if page is not None:
1019+
__body["page"] = page
10171020
if pretty is not None:
10181021
__query["pretty"] = pretty
10191022
if size is not None:
@@ -2812,10 +2815,10 @@ async def put_job(
28122815
*,
28132816
job_id: Any,
28142817
analysis_config: Any,
2815-
background_persist_interval: Any,
28162818
data_description: Any,
28172819
allow_lazy_open: Optional[bool] = None,
28182820
analysis_limits: Optional[Any] = None,
2821+
background_persist_interval: Optional[Any] = None,
28192822
custom_settings: Optional[Any] = None,
28202823
daily_model_snapshot_retention_after_days: Optional[int] = None,
28212824
datafeed_config: Optional[Any] = None,
@@ -2842,12 +2845,6 @@ async def put_job(
28422845
:param analysis_config: Specifies how to analyze the data. After you create a
28432846
job, you cannot change the analysis configuration; all the properties are
28442847
informational.
2845-
:param background_persist_interval: Advanced configuration option. The time between
2846-
each periodic persistence of the model. The default value is a randomized
2847-
value between 3 to 4 hours, which avoids all jobs persisting at exactly the
2848-
same time. The smallest allowed value is 1 hour. For very large models (several
2849-
GB), persistence could take 10-20 minutes, so do not set the `background_persist_interval`
2850-
value too low.
28512848
:param data_description: Defines the format of the input data when you send data
28522849
to the job by using the post data API. Note that when configure a datafeed,
28532850
these properties are automatically set. When data is received via the post
@@ -2866,6 +2863,12 @@ async def put_job(
28662863
the mathematical models in memory. These limits are approximate and can be
28672864
set per job. They do not control the memory used by other processes, for
28682865
example the Elasticsearch Java processes.
2866+
:param background_persist_interval: Advanced configuration option. The time between
2867+
each periodic persistence of the model. The default value is a randomized
2868+
value between 3 to 4 hours, which avoids all jobs persisting at exactly the
2869+
same time. The smallest allowed value is 1 hour. For very large models (several
2870+
GB), persistence could take 10-20 minutes, so do not set the `background_persist_interval`
2871+
value too low.
28692872
:param custom_settings: Advanced configuration option. Contains custom meta data
28702873
about the job.
28712874
:param daily_model_snapshot_retention_after_days: Advanced configuration option,
@@ -2913,25 +2916,21 @@ async def put_job(
29132916
raise ValueError("Empty value passed for parameter 'job_id'")
29142917
if analysis_config is None:
29152918
raise ValueError("Empty value passed for parameter 'analysis_config'")
2916-
if background_persist_interval is None:
2917-
raise ValueError(
2918-
"Empty value passed for parameter 'background_persist_interval'"
2919-
)
29202919
if data_description is None:
29212920
raise ValueError("Empty value passed for parameter 'data_description'")
29222921
__path = f"/_ml/anomaly_detectors/{_quote(job_id)}"
29232922
__body: Dict[str, Any] = {}
29242923
__query: Dict[str, Any] = {}
29252924
if analysis_config is not None:
29262925
__body["analysis_config"] = analysis_config
2927-
if background_persist_interval is not None:
2928-
__body["background_persist_interval"] = background_persist_interval
29292926
if data_description is not None:
29302927
__body["data_description"] = data_description
29312928
if allow_lazy_open is not None:
29322929
__body["allow_lazy_open"] = allow_lazy_open
29332930
if analysis_limits is not None:
29342931
__body["analysis_limits"] = analysis_limits
2932+
if background_persist_interval is not None:
2933+
__body["background_persist_interval"] = background_persist_interval
29352934
if custom_settings is not None:
29362935
__body["custom_settings"] = custom_settings
29372936
if daily_model_snapshot_retention_after_days is not None:

elasticsearch/_sync/client/__init__.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,15 +33,16 @@
3333

3434
from elastic_transport import (
3535
BaseNode,
36+
HeadApiResponse,
3637
NodeConfig,
3738
NodePool,
3839
NodeSelector,
3940
Serializer,
4041
Transport,
41-
TransportError,
4242
)
4343
from elastic_transport.client_utils import DEFAULT, DefaultType
4444

45+
from ...exceptions import ApiError
4546
from ...serializer import DEFAULT_SERIALIZERS
4647
from ._base import (
4748
BaseClient,
@@ -456,7 +457,7 @@ def ping(
456457
filter_path: Optional[Union[List[str], str]] = None,
457458
human: Optional[bool] = None,
458459
pretty: Optional[bool] = None,
459-
) -> bool:
460+
) -> Any:
460461
"""
461462
Returns basic information about the cluster.
462463
@@ -479,9 +480,9 @@ def ping(
479480
__headers = {"accept": "application/json"}
480481
try:
481482
resp = self._perform_request("HEAD", __target, headers=__headers)
482-
return bool(resp)
483-
except TransportError:
484-
return False
483+
return resp
484+
except ApiError as e:
485+
return HeadApiResponse(meta=e.meta)
485486

486487
# AUTO-GENERATED-API-DEFINITIONS #
487488

@@ -2071,7 +2072,6 @@ def info(
20712072
@_rewrite_parameters(
20722073
body_fields=True,
20732074
parameter_aliases={"_source": "source"},
2074-
ignore_deprecated_options=True,
20752075
)
20762076
def knn_search(
20772077
self,

elasticsearch/_sync/client/ml.py

Lines changed: 22 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -948,6 +948,7 @@ def get_buckets(
948948
filter_path: Optional[Union[List[str], str]] = None,
949949
from_: Optional[int] = None,
950950
human: Optional[bool] = None,
951+
page: Optional[Any] = None,
951952
pretty: Optional[bool] = None,
952953
size: Optional[int] = None,
953954
sort: Optional[Any] = None,
@@ -961,18 +962,18 @@ def get_buckets(
961962
:param job_id: Identifier for the anomaly detection job.
962963
:param timestamp: The timestamp of a single bucket result. If you do not specify
963964
this parameter, the API returns information about all buckets.
964-
:param anomaly_score: Returns buckets with anomaly scores greater or equal than
965-
this value.
966-
:param desc: If `true`, the buckets are sorted in descending order.
967-
:param end: Returns buckets with timestamps earlier than this time. `-1` means
968-
it is unset and results are not limited to specific timestamps.
969-
:param exclude_interim: If `true`, the output excludes interim results.
970-
:param expand: If true, the output includes anomaly records.
965+
:param anomaly_score: Refer to the description for the `anomaly_score` query
966+
parameter.
967+
:param desc: Refer to the description for the `desc` query parameter.
968+
:param end: Refer to the description for the `end` query parameter.
969+
:param exclude_interim: Refer to the description for the `exclude_interim` query
970+
parameter.
971+
:param expand: Refer to the description for the `expand` query parameter.
971972
:param from_: Skips the specified number of buckets.
973+
:param page:
972974
:param size: Specifies the maximum number of buckets to obtain.
973-
:param sort: Specifies the sort field for the requested buckets.
974-
:param start: Returns buckets with timestamps after this time. `-1` means it
975-
is unset and results are not limited to specific timestamps.
975+
:param sort: Refer to the desription for the `sort` query parameter.
976+
:param start: Refer to the description for the `start` query parameter.
976977
"""
977978
if job_id in SKIP_IN_PATH:
978979
raise ValueError("Empty value passed for parameter 'job_id'")
@@ -1002,6 +1003,8 @@ def get_buckets(
10021003
__query["from"] = from_
10031004
if human is not None:
10041005
__query["human"] = human
1006+
if page is not None:
1007+
__body["page"] = page
10051008
if pretty is not None:
10061009
__query["pretty"] = pretty
10071010
if size is not None:
@@ -2770,10 +2773,10 @@ def put_job(
27702773
*,
27712774
job_id: Any,
27722775
analysis_config: Any,
2773-
background_persist_interval: Any,
27742776
data_description: Any,
27752777
allow_lazy_open: Optional[bool] = None,
27762778
analysis_limits: Optional[Any] = None,
2779+
background_persist_interval: Optional[Any] = None,
27772780
custom_settings: Optional[Any] = None,
27782781
daily_model_snapshot_retention_after_days: Optional[int] = None,
27792782
datafeed_config: Optional[Any] = None,
@@ -2800,12 +2803,6 @@ def put_job(
28002803
:param analysis_config: Specifies how to analyze the data. After you create a
28012804
job, you cannot change the analysis configuration; all the properties are
28022805
informational.
2803-
:param background_persist_interval: Advanced configuration option. The time between
2804-
each periodic persistence of the model. The default value is a randomized
2805-
value between 3 to 4 hours, which avoids all jobs persisting at exactly the
2806-
same time. The smallest allowed value is 1 hour. For very large models (several
2807-
GB), persistence could take 10-20 minutes, so do not set the `background_persist_interval`
2808-
value too low.
28092806
:param data_description: Defines the format of the input data when you send data
28102807
to the job by using the post data API. Note that when configure a datafeed,
28112808
these properties are automatically set. When data is received via the post
@@ -2824,6 +2821,12 @@ def put_job(
28242821
the mathematical models in memory. These limits are approximate and can be
28252822
set per job. They do not control the memory used by other processes, for
28262823
example the Elasticsearch Java processes.
2824+
:param background_persist_interval: Advanced configuration option. The time between
2825+
each periodic persistence of the model. The default value is a randomized
2826+
value between 3 to 4 hours, which avoids all jobs persisting at exactly the
2827+
same time. The smallest allowed value is 1 hour. For very large models (several
2828+
GB), persistence could take 10-20 minutes, so do not set the `background_persist_interval`
2829+
value too low.
28272830
:param custom_settings: Advanced configuration option. Contains custom meta data
28282831
about the job.
28292832
:param daily_model_snapshot_retention_after_days: Advanced configuration option,
@@ -2871,25 +2874,21 @@ def put_job(
28712874
raise ValueError("Empty value passed for parameter 'job_id'")
28722875
if analysis_config is None:
28732876
raise ValueError("Empty value passed for parameter 'analysis_config'")
2874-
if background_persist_interval is None:
2875-
raise ValueError(
2876-
"Empty value passed for parameter 'background_persist_interval'"
2877-
)
28782877
if data_description is None:
28792878
raise ValueError("Empty value passed for parameter 'data_description'")
28802879
__path = f"/_ml/anomaly_detectors/{_quote(job_id)}"
28812880
__body: Dict[str, Any] = {}
28822881
__query: Dict[str, Any] = {}
28832882
if analysis_config is not None:
28842883
__body["analysis_config"] = analysis_config
2885-
if background_persist_interval is not None:
2886-
__body["background_persist_interval"] = background_persist_interval
28872884
if data_description is not None:
28882885
__body["data_description"] = data_description
28892886
if allow_lazy_open is not None:
28902887
__body["allow_lazy_open"] = allow_lazy_open
28912888
if analysis_limits is not None:
28922889
__body["analysis_limits"] = analysis_limits
2890+
if background_persist_interval is not None:
2891+
__body["background_persist_interval"] = background_persist_interval
28932892
if custom_settings is not None:
28942893
__body["custom_settings"] = custom_settings
28952894
if daily_model_snapshot_retention_after_days is not None:

elasticsearch/_sync/client/utils.py

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -255,7 +255,7 @@ def _rewrite_parameters(
255255
body_name: Optional[str] = None,
256256
body_fields: bool = False,
257257
parameter_aliases: Optional[Dict[str, str]] = None,
258-
ignore_deprecated_options: Optional[Union[bool, Set[str]]] = None,
258+
ignore_deprecated_options: Optional[Set[str]] = None,
259259
) -> Callable[[Callable[..., RT]], Callable[..., RT]]:
260260
def wrapper(api: Callable[..., RT]) -> Callable[..., RT]:
261261
@wraps(api)
@@ -264,8 +264,7 @@ def wrapped(*args: Any, **kwargs: Any) -> RT:
264264

265265
# We merge 'params' first as transport options can be specified using params.
266266
if "params" in kwargs and (
267-
ignore_deprecated_options is not True
268-
or ignore_deprecated_options is not None
267+
not ignore_deprecated_options
269268
or "params" not in ignore_deprecated_options
270269
):
271270
params = kwargs.pop("params")
@@ -277,15 +276,14 @@ def wrapped(*args: Any, **kwargs: Any) -> RT:
277276
)
278277
_merge_kwargs_no_duplicates(kwargs, params)
279278

280-
if ignore_deprecated_options is not True:
279+
maybe_transport_options = _TRANSPORT_OPTIONS.intersection(kwargs)
280+
if maybe_transport_options:
281281
transport_options = {}
282-
options_to_skip: Set[str] = (
283-
ignore_deprecated_options
284-
if isinstance(ignore_deprecated_options, set)
285-
else set()
286-
)
287-
for option in _TRANSPORT_OPTIONS:
288-
if option in options_to_skip:
282+
for option in maybe_transport_options:
283+
if (
284+
ignore_deprecated_options
285+
and option in ignore_deprecated_options
286+
):
289287
continue
290288
try:
291289
option_rename = option
@@ -315,7 +313,9 @@ def wrapped(*args: Any, **kwargs: Any) -> RT:
315313
client = namespaced_client(client)
316314
args = (client,) + args[1:]
317315

318-
if "body" in kwargs and ignore_deprecated_options is not True:
316+
if "body" in kwargs and (
317+
not ignore_deprecated_options or "body" not in ignore_deprecated_options
318+
):
319319
body = kwargs.pop("body")
320320
if body is not None:
321321
if body_name:

test_elasticsearch/test_server/test_rest_api_spec.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040

4141
# some params had to be changed in python, keep track of them so we can rename
4242
# those in the tests accordingly
43-
PARAMS_RENAMES = {"type": "doc_type", "from": "from_"}
43+
PARAMS_RENAMES = {"from": "from_"}
4444
API_PARAMS_RENAMES = {
4545
"snapshot.create_repository": {"repository": "name"},
4646
"snapshot.delete_repository": {"repository": "name"},

0 commit comments

Comments
 (0)