Skip to content

Commit 39d800c

Browse files
committed
Skip tests where APIs are intentionally used incorrectly
1 parent 7cf4cb9 commit 39d800c

File tree

6 files changed

+383
-32
lines changed

6 files changed

+383
-32
lines changed

elasticsearch/_async/client/indices.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2908,21 +2908,20 @@ async def simulate_index_template(
29082908
async def simulate_template(
29092909
self,
29102910
*,
2911-
template: Any,
29122911
name: Optional[Any] = None,
29132912
create: Optional[bool] = None,
29142913
error_trace: Optional[bool] = None,
29152914
filter_path: Optional[Union[List[str], str]] = None,
29162915
human: Optional[bool] = None,
29172916
master_timeout: Optional[Any] = None,
29182917
pretty: Optional[bool] = None,
2918+
template: Optional[Any] = None,
29192919
) -> Any:
29202920
"""
29212921
Simulate resolving the given template name or body
29222922
29232923
`<https://www.elastic.co/guide/en/elasticsearch/reference/master/indices-templates.html>`_
29242924
2925-
:param template:
29262925
:param name: Name of the index template to simulate. To test a template configuration
29272926
before you add it to the cluster, omit this parameter and specify the template
29282927
configuration in the request body.
@@ -2933,9 +2932,8 @@ async def simulate_template(
29332932
:param master_timeout: Period to wait for a connection to the master node. If
29342933
no response is received before the timeout expires, the request fails and
29352934
returns an error.
2935+
:param template:
29362936
"""
2937-
if template is None:
2938-
raise ValueError("Empty value passed for parameter 'template'")
29392937
if name not in SKIP_IN_PATH:
29402938
__path = f"/_index_template/_simulate/{_quote(name)}"
29412939
else:

elasticsearch/_async/client/ml.py

Lines changed: 184 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1724,6 +1724,7 @@ async def get_model_snapshots(
17241724
filter_path: Optional[Union[List[str], str]] = None,
17251725
from_: Optional[int] = None,
17261726
human: Optional[bool] = None,
1727+
page: Optional[Any] = None,
17271728
pretty: Optional[bool] = None,
17281729
size: Optional[int] = None,
17291730
sort: Optional[Any] = None,
@@ -1736,16 +1737,17 @@ async def get_model_snapshots(
17361737
17371738
:param job_id: Identifier for the anomaly detection job.
17381739
:param snapshot_id: A numerical character string that uniquely identifies the
1739-
model snapshot.
1740-
:param desc: If true, the results are sorted in descending order.
1741-
:param end: Returns snapshots with timestamps earlier than this time. Defaults
1742-
to unset, which means results are not limited to specific timestamps.
1740+
model snapshot. You can get information for multiple snapshots by using a
1741+
comma-separated list or a wildcard expression. You can get all snapshots
1742+
by using `_all`, by specifying `*` as the snapshot ID, or by omitting the
1743+
snapshot ID.
1744+
:param desc: Refer to the description for the `desc` query parameter.
1745+
:param end: Refer to the description for the `end` query parameter.
17431746
:param from_: Skips the specified number of snapshots.
1747+
:param page:
17441748
:param size: Specifies the maximum number of snapshots to obtain.
1745-
:param sort: Specifies the sort field for the requested snapshots. By default,
1746-
the snapshots are sorted by their timestamp.
1747-
:param start: Returns snapshots with timestamps after this time. Defaults to
1748-
unset, which means results are not limited to specific timestamps.
1749+
:param sort: Refer to the description for the `sort` query parameter.
1750+
:param start: Refer to the description for the `start` query parameter.
17491751
"""
17501752
if job_id in SKIP_IN_PATH:
17511753
raise ValueError("Empty value passed for parameter 'job_id'")
@@ -1755,10 +1757,10 @@ async def get_model_snapshots(
17551757
__path = f"/_ml/anomaly_detectors/{_quote(job_id)}/model_snapshots"
17561758
else:
17571759
raise ValueError("Couldn't find a path for the given parameters")
1758-
__query: Dict[str, Any] = {}
17591760
__body: Dict[str, Any] = {}
1761+
__query: Dict[str, Any] = {}
17601762
if desc is not None:
1761-
__query["desc"] = desc
1763+
__body["desc"] = desc
17621764
if end is not None:
17631765
__body["end"] = end
17641766
if error_trace is not None:
@@ -1769,12 +1771,14 @@ async def get_model_snapshots(
17691771
__query["from"] = from_
17701772
if human is not None:
17711773
__query["human"] = human
1774+
if page is not None:
1775+
__body["page"] = page
17721776
if pretty is not None:
17731777
__query["pretty"] = pretty
17741778
if size is not None:
17751779
__query["size"] = size
17761780
if sort is not None:
1777-
__query["sort"] = sort
1781+
__body["sort"] = sort
17781782
if start is not None:
17791783
__body["start"] = start
17801784
if not __body:
@@ -3528,6 +3532,175 @@ async def update_data_frame_analytics(
35283532
"POST", __target, headers=__headers, body=__body
35293533
)
35303534

3535+
@_rewrite_parameters(
3536+
body_fields=True,
3537+
)
3538+
async def update_datafeed(
3539+
self,
3540+
*,
3541+
datafeed_id: Any,
3542+
aggregations: Optional[Dict[str, Any]] = None,
3543+
allow_no_indices: Optional[bool] = None,
3544+
chunking_config: Optional[Any] = None,
3545+
delayed_data_check_config: Optional[Any] = None,
3546+
error_trace: Optional[bool] = None,
3547+
expand_wildcards: Optional[Any] = None,
3548+
filter_path: Optional[Union[List[str], str]] = None,
3549+
frequency: Optional[Any] = None,
3550+
human: Optional[bool] = None,
3551+
ignore_throttled: Optional[bool] = None,
3552+
ignore_unavailable: Optional[bool] = None,
3553+
indexes: Optional[List[str]] = None,
3554+
indices: Optional[List[str]] = None,
3555+
indices_options: Optional[Any] = None,
3556+
max_empty_searches: Optional[int] = None,
3557+
pretty: Optional[bool] = None,
3558+
query: Optional[Any] = None,
3559+
query_delay: Optional[Any] = None,
3560+
runtime_mappings: Optional[Any] = None,
3561+
script_fields: Optional[Dict[str, Any]] = None,
3562+
scroll_size: Optional[int] = None,
3563+
) -> Any:
3564+
"""
3565+
Updates certain properties of a datafeed.
3566+
3567+
`<https://www.elastic.co/guide/en/elasticsearch/reference/current/ml-update-datafeed.html>`_
3568+
3569+
:param datafeed_id: A numerical character string that uniquely identifies the
3570+
datafeed. This identifier can contain lowercase alphanumeric characters (a-z
3571+
and 0-9), hyphens, and underscores. It must start and end with alphanumeric
3572+
characters.
3573+
:param aggregations: If set, the datafeed performs aggregation searches. Support
3574+
for aggregations is limited and should be used only with low cardinality
3575+
data.
3576+
:param allow_no_indices: If `true`, wildcard indices expressions that resolve
3577+
into no concrete indices are ignored. This includes the `_all` string or
3578+
when no indices are specified.
3579+
:param chunking_config: Datafeeds might search over long time periods, for several
3580+
months or years. This search is split into time chunks in order to ensure
3581+
the load on Elasticsearch is managed. Chunking configuration controls how
3582+
the size of these time chunks are calculated; it is an advanced configuration
3583+
option.
3584+
:param delayed_data_check_config: Specifies whether the datafeed checks for missing
3585+
data and the size of the window. The datafeed can optionally search over
3586+
indices that have already been read in an effort to determine whether any
3587+
data has subsequently been added to the index. If missing data is found,
3588+
it is a good indication that the `query_delay` is set too low and the data
3589+
is being indexed after the datafeed has passed that moment in time. This
3590+
check runs only on real-time datafeeds.
3591+
:param expand_wildcards: Type of index that wildcard patterns can match. If the
3592+
request can target data streams, this argument determines whether wildcard
3593+
expressions match hidden data streams. Supports comma-separated values. Valid
3594+
values are: * `all`: Match any data stream or index, including hidden ones.
3595+
* `closed`: Match closed, non-hidden indices. Also matches any non-hidden
3596+
data stream. Data streams cannot be closed. * `hidden`: Match hidden data
3597+
streams and hidden indices. Must be combined with `open`, `closed`, or both.
3598+
* `none`: Wildcard patterns are not accepted. * `open`: Match open, non-hidden
3599+
indices. Also matches any non-hidden data stream.
3600+
:param frequency: The interval at which scheduled queries are made while the
3601+
datafeed runs in real time. The default value is either the bucket span for
3602+
short bucket spans, or, for longer bucket spans, a sensible fraction of the
3603+
bucket span. When `frequency` is shorter than the bucket span, interim results
3604+
for the last (partial) bucket are written then eventually overwritten by
3605+
the full bucket results. If the datafeed uses aggregations, this value must
3606+
be divisible by the interval of the date histogram aggregation.
3607+
:param ignore_throttled: If `true`, concrete, expanded or aliased indices are
3608+
ignored when frozen.
3609+
:param ignore_unavailable: If `true`, unavailable indices (missing or closed)
3610+
are ignored.
3611+
:param indexes: An array of index names. Wildcards are supported. If any of the
3612+
indices are in remote clusters, the machine learning nodes must have the
3613+
`remote_cluster_client` role.
3614+
:param indices: An array of index names. Wildcards are supported. If any of the
3615+
indices are in remote clusters, the machine learning nodes must have the
3616+
`remote_cluster_client` role.
3617+
:param indices_options: Specifies index expansion options that are used during
3618+
search.
3619+
:param max_empty_searches: If a real-time datafeed has never seen any data (including
3620+
during any initial training period), it automatically stops and closes the
3621+
associated job after this many real-time searches return no documents. In
3622+
other words, it stops after `frequency` times `max_empty_searches` of real-time
3623+
operation. If not set, a datafeed with no end time that sees no data remains
3624+
started until it is explicitly stopped. By default, it is not set.
3625+
:param query: The Elasticsearch query domain-specific language (DSL). This value
3626+
corresponds to the query object in an Elasticsearch search POST body. All
3627+
the options that are supported by Elasticsearch can be used, as this object
3628+
is passed verbatim to Elasticsearch. Note that if you change the query, the
3629+
analyzed data is also changed. Therefore, the time required to learn might
3630+
be long and the understandability of the results is unpredictable. If you
3631+
want to make significant changes to the source data, it is recommended that
3632+
you clone the job and datafeed and make the amendments in the clone. Let
3633+
both run in parallel and close one when you are satisfied with the results
3634+
of the job.
3635+
:param query_delay: The number of seconds behind real time that data is queried.
3636+
For example, if data from 10:04 a.m. might not be searchable in Elasticsearch
3637+
until 10:06 a.m., set this property to 120 seconds. The default value is
3638+
randomly selected between `60s` and `120s`. This randomness improves the
3639+
query performance when there are multiple jobs running on the same node.
3640+
:param runtime_mappings: Specifies runtime fields for the datafeed search.
3641+
:param script_fields: Specifies scripts that evaluate custom expressions and
3642+
returns script fields to the datafeed. The detector configuration objects
3643+
in a job can contain functions that use these script fields.
3644+
:param scroll_size: The size parameter that is used in Elasticsearch searches
3645+
when the datafeed does not use aggregations. The maximum value is the value
3646+
of `index.max_result_window`.
3647+
"""
3648+
if datafeed_id in SKIP_IN_PATH:
3649+
raise ValueError("Empty value passed for parameter 'datafeed_id'")
3650+
__path = f"/_ml/datafeeds/{_quote(datafeed_id)}/_update"
3651+
__body: Dict[str, Any] = {}
3652+
__query: Dict[str, Any] = {}
3653+
if aggregations is not None:
3654+
__body["aggregations"] = aggregations
3655+
if allow_no_indices is not None:
3656+
__query["allow_no_indices"] = allow_no_indices
3657+
if chunking_config is not None:
3658+
__body["chunking_config"] = chunking_config
3659+
if delayed_data_check_config is not None:
3660+
__body["delayed_data_check_config"] = delayed_data_check_config
3661+
if error_trace is not None:
3662+
__query["error_trace"] = error_trace
3663+
if expand_wildcards is not None:
3664+
__query["expand_wildcards"] = expand_wildcards
3665+
if filter_path is not None:
3666+
__query["filter_path"] = filter_path
3667+
if frequency is not None:
3668+
__body["frequency"] = frequency
3669+
if human is not None:
3670+
__query["human"] = human
3671+
if ignore_throttled is not None:
3672+
__query["ignore_throttled"] = ignore_throttled
3673+
if ignore_unavailable is not None:
3674+
__query["ignore_unavailable"] = ignore_unavailable
3675+
if indexes is not None:
3676+
__body["indexes"] = indexes
3677+
if indices is not None:
3678+
__body["indices"] = indices
3679+
if indices_options is not None:
3680+
__body["indices_options"] = indices_options
3681+
if max_empty_searches is not None:
3682+
__body["max_empty_searches"] = max_empty_searches
3683+
if pretty is not None:
3684+
__query["pretty"] = pretty
3685+
if query is not None:
3686+
__body["query"] = query
3687+
if query_delay is not None:
3688+
__body["query_delay"] = query_delay
3689+
if runtime_mappings is not None:
3690+
__body["runtime_mappings"] = runtime_mappings
3691+
if script_fields is not None:
3692+
__body["script_fields"] = script_fields
3693+
if scroll_size is not None:
3694+
__body["scroll_size"] = scroll_size
3695+
if __query:
3696+
__target = f"{__path}?{_quote_query(__query)}"
3697+
else:
3698+
__target = __path
3699+
__headers = {"accept": "application/json", "content-type": "application/json"}
3700+
return await self._perform_request(
3701+
"POST", __target, headers=__headers, body=__body
3702+
)
3703+
35313704
@_rewrite_parameters(
35323705
body_fields=True,
35333706
)

elasticsearch/_sync/client/indices.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2886,21 +2886,20 @@ def simulate_index_template(
28862886
def simulate_template(
28872887
self,
28882888
*,
2889-
template: Any,
28902889
name: Optional[Any] = None,
28912890
create: Optional[bool] = None,
28922891
error_trace: Optional[bool] = None,
28932892
filter_path: Optional[Union[List[str], str]] = None,
28942893
human: Optional[bool] = None,
28952894
master_timeout: Optional[Any] = None,
28962895
pretty: Optional[bool] = None,
2896+
template: Optional[Any] = None,
28972897
) -> Any:
28982898
"""
28992899
Simulate resolving the given template name or body
29002900
29012901
`<https://www.elastic.co/guide/en/elasticsearch/reference/master/indices-templates.html>`_
29022902
2903-
:param template:
29042903
:param name: Name of the index template to simulate. To test a template configuration
29052904
before you add it to the cluster, omit this parameter and specify the template
29062905
configuration in the request body.
@@ -2911,9 +2910,8 @@ def simulate_template(
29112910
:param master_timeout: Period to wait for a connection to the master node. If
29122911
no response is received before the timeout expires, the request fails and
29132912
returns an error.
2913+
:param template:
29142914
"""
2915-
if template is None:
2916-
raise ValueError("Empty value passed for parameter 'template'")
29172915
if name not in SKIP_IN_PATH:
29182916
__path = f"/_index_template/_simulate/{_quote(name)}"
29192917
else:

0 commit comments

Comments
 (0)