diff --git a/elasticsearch/_async/client/__init__.py b/elasticsearch/_async/client/__init__.py index 0497607c2..365f1b1df 100644 --- a/elasticsearch/_async/client/__init__.py +++ b/elasticsearch/_async/client/__init__.py @@ -1010,9 +1010,9 @@ async def get(self, index, id, doc_type=None, params=None, headers=None): to include in the response. :arg preference: Specifies the node or shard the operation should be performed on. Random by default. - :arg realtime: Boolean) If true, the request is real-time as + :arg realtime: Boolean) If true, the request is real-time as opposed to near-real-time. Default: True - :arg refresh: If true, Elasticsearch refreshes the affected + :arg refresh: If true, Elasticsearch refreshes the affected shards to make this operation visible to search. If false, do nothing with refreshes. :arg routing: Target the specified primary shard. @@ -1614,8 +1614,8 @@ async def search( :arg doc_type: A comma-separated list of document types to search; leave empty to perform the operation on all types :arg _source: Indicates which source fields are returned for - matching documents. These fields are returned in the hits._source - property of the search response. + matching documents. These + fields are returned in the hits._source property of the search response. :arg _source_excludes: A list of fields to exclude from the returned _source field :arg _source_includes: A list of fields to extract and return @@ -1645,19 +1645,22 @@ async def search( :arg df: The field to use as default where no field prefix is given in the query string :arg docvalue_fields: Array of wildcard (*) patterns. The - request returns doc values for field names matching these patterns in - the hits.fields property of the response. + request returns doc values for field + names matching these patterns in the hits.fields property of the + response. :arg expand_wildcards: Whether to expand wildcard expression to concrete indices that are open, closed or both. Valid choices: open, closed, hidden, none, all Default: open :arg explain: If true, returns detailed information about score computation as part of a hit. :arg fields: Array of wildcard (*) patterns. The request returns - values for field names matching these patterns in the hits.fields - property of the response. + values for field names + matching these patterns in the hits.fields property of the response. :arg from_: Starting document offset. By default, you cannot - page through more than 10,000 hits using the from and size parameters. - To page through more hits, use the search_after parameter. + page through more than 10,000 + hits using the from and size parameters. To page through more hits, use + the + search_after parameter. :arg highlight: :arg ignore_throttled: Whether specified concrete, expanded or aliased indices should be ignored when throttled @@ -1675,13 +1678,15 @@ async def search( that all shards involved in search should have for this request to be successful :arg min_score: Minimum _score for matching documents. Documents - with a lower _score are not included in the search results. + with a lower _score are + not included in the search results. :arg pit: Limits the search to a point in time (PIT). If you - provide a PIT, you cannot specify an in the request path. + provide a PIT, you + cannot specify an in the request path. :arg post_filter: :arg pre_filter_shard_size: A threshold that enforces a pre- filter roundtrip to prefilter search shards based on query rewriting if - the number of shards the search request expands to exceeds the + the number of shards the search request expands to exceeds the threshold. This filter roundtrip can limit the number of shards significantly if for instance a shard can not match any documents based on its rewrite method ie. if date filters are mandatory to match but the @@ -1698,8 +1703,8 @@ async def search( be rendered as an integer or an object in the rest search response :arg routing: A comma-separated list of specific routing values :arg runtime_mappings: Defines one or more runtime fields in the - search request. These fields take precedence over mapped fields with the - same name. + search request. These fields take + precedence over mapped fields with the same name. :arg script_fields: Retrieve a script evaluation (based on different fields) for each hit. :arg scroll: Specify how long a consistent view of the index @@ -1708,21 +1713,27 @@ async def search( :arg search_type: Search operation type Valid choices: query_then_fetch, dfs_query_then_fetch :arg seq_no_primary_term: If true, returns sequence number and - primary term of the last modification of each hit. See Optimistic - concurrency control. + primary term of the last modification + of each hit. See Optimistic concurrency control. :arg size: The number of hits to return. By default, you cannot - page through more than 10,000 hits using the from and size parameters. - To page through more hits, use the search_after parameter. + page through more + than 10,000 hits using the from and size parameters. To page through + more + hits, use the search_after parameter. :arg slice: :arg sort: :arg stats: Stats groups to associate with the search. Each - group maintains a statistics aggregation for its associated searches. - You can retrieve these stats using the indices stats API. + group maintains a statistics + aggregation for its associated searches. You can retrieve these stats + using + the indices stats API. :arg stored_fields: List of stored fields to return as part of a - hit. If no fields are specified, no stored fields are included in the - response. If this field is specified, the _source parameter defaults to - false. You can pass _source: true to return both source fields and - stored fields in the search response. + hit. If no fields are specified, + no stored fields are included in the response. If this field is + specified, the _source + parameter defaults to false. You can pass _source: true to return both + source fields + and stored fields in the search response. :arg suggest: :arg suggest_field: Specifies which field to use for suggestions. @@ -1732,18 +1743,24 @@ async def search( :arg suggest_text: The source text for which the suggestions should be returned. :arg terminate_after: Maximum number of documents to collect for - each shard. If a query reaches this limit, Elasticsearch terminates the - query early. Elasticsearch collects documents before sorting. Defaults - to 0, which does not terminate query execution early. + each shard. If a query reaches this + limit, Elasticsearch terminates the query early. Elasticsearch collects + documents + before sorting. Defaults to 0, which does not terminate query execution + early. :arg timeout: Specifies the period of time to wait for a - response from each shard. If no response is received before the timeout - expires, the request fails and returns an error. Defaults to no timeout. + response from each shard. If no response + is received before the timeout expires, the request fails and returns an + error. + Defaults to no timeout. :arg track_scores: If true, calculate and return document scores, even if the scores are not used for sorting. :arg track_total_hits: Number of hits matching the query to - count accurately. If true, the exact number of hits is returned at the - cost of some performance. If false, the response does not include the - total number of hits matching the query. Defaults to 10,000 hits. + count accurately. If true, the exact + number of hits is returned at the cost of some performance. If false, + the + response does not include the total number of hits matching the query. + Defaults to 10,000 hits. :arg typed_keys: Specify whether aggregation and suggester names should be prefixed by their respective types in the response :arg version: If true, returns document version as part of a @@ -1945,6 +1962,7 @@ async def termvectors( "scripted_upsert", "upsert", ], + body_required=True, ) async def update(self, index, id, body, doc_type=None, params=None, headers=None): """ @@ -1958,13 +1976,15 @@ async def update(self, index, id, body, doc_type=None, params=None, headers=None partial `doc` :arg doc_type: The type of the document :arg _source: Set to false to disable source retrieval. You can - also specify a comma-separated list of the fields you want to retrieve. + also specify a comma-separated + list of the fields you want to retrieve. :arg _source_excludes: Specify the source fields you want to exclude. :arg _source_includes: Specify the source fields you want to retrieve. :arg detect_noop: Set to false to disable setting 'result' in - the response to 'noop' if no change to the document occurred. + the response + to 'noop' if no change to the document occurred. :arg doc: A partial update to an existing document. :arg doc_as_upsert: Set to true to use the contents of 'doc' as the value of 'upsert' @@ -1974,10 +1994,11 @@ async def update(self, index, id, body, doc_type=None, params=None, headers=None this sequence number. :arg lang: The script language. Default: painless :arg refresh: If 'true', Elasticsearch refreshes the affected - shards to make this operation visible to search, if 'wait_for' then wait - for a refresh to make this operation visible to search, if 'false' do - nothing with refreshes. Valid choices: true, false, wait_for Default: - false + shards to make this operation + visible to search, if 'wait_for' then wait for a refresh to make this + operation + visible to search, if 'false' do nothing with refreshes. Valid choices: + true, false, wait_for Default: false :arg require_alias: If true, the destination must be an index alias. :arg retry_on_conflict: Specify how many times should the @@ -1988,15 +2009,18 @@ async def update(self, index, id, body, doc_type=None, params=None, headers=None :arg scripted_upsert: Set to true to execute the script whether or not the document exists. :arg timeout: Period to wait for dynamic mapping updates and - active shards. This guarantees Elasticsearch waits for at least the - timeout before failing. The actual wait time could be longer, - particularly when multiple waits occur. Default: 1m + active shards. + This guarantees Elasticsearch waits for at least the timeout before + failing. + The actual wait time could be longer, particularly when multiple waits + occur. Default: 1m :arg upsert: If the document does not already exist, the - contents of 'upsert' are inserted as a new document. If the document - exists, the 'script' is executed. + contents of 'upsert' are inserted as a + new document. If the document exists, the 'script' is executed. :arg wait_for_active_shards: The number of shard copies that - must be active before proceeding with the operations. Set to 'all' or - any positive integer up to the total number of shards in the index + must be active before proceeding with the operations. + Set to 'all' or any positive integer up to the total number of shards in + the index (number_of_replicas+1). Defaults to 1 meaning the primary shard. Default: 1 """ diff --git a/elasticsearch/_async/client/__init__.pyi b/elasticsearch/_async/client/__init__.pyi index ff80b312a..c9899d56b 100644 --- a/elasticsearch/_async/client/__init__.pyi +++ b/elasticsearch/_async/client/__init__.pyi @@ -440,7 +440,7 @@ class AsyncElasticsearch(object): api_key: Optional[Union[str, Tuple[str, str]]] = ..., params: Optional[MutableMapping[str, Any]] = ..., headers: Optional[MutableMapping[str, str]] = ..., - ) -> Any: ... + ) -> bool: ... async def exists_source( self, *, diff --git a/elasticsearch/_async/client/indices.py b/elasticsearch/_async/client/indices.py index 7d26d838a..303156b6f 100644 --- a/elasticsearch/_async/client/indices.py +++ b/elasticsearch/_async/client/indices.py @@ -99,7 +99,11 @@ async def flush(self, index=None, params=None, headers=None): ) @query_params( - "include_type_name", "master_timeout", "timeout", "wait_for_active_shards" + "include_type_name", + "master_timeout", + "timeout", + "wait_for_active_shards", + body_params=["aliases", "mappings", "settings"], ) async def create(self, index, body=None, params=None, headers=None): """ @@ -110,9 +114,16 @@ async def create(self, index, body=None, params=None, headers=None): :arg index: The name of the index :arg body: The configuration for the index (`settings` and `mappings`) + :arg aliases: :arg include_type_name: Whether a type should be expected in the body of the mappings. + :arg mappings: Mapping for fields in the index. If specified, + this mapping can include: + - Field names + - Field data types + - Mapping parameters :arg master_timeout: Specify timeout for connection to master + :arg settings: :arg timeout: Explicit operation timeout :arg wait_for_active_shards: Set the number of active shards to wait for before the operation returns. @@ -168,23 +179,29 @@ async def get(self, index, params=None, headers=None): ``_ - :arg index: A comma-separated list of index names + :arg index: Comma-separated list of data streams, indices, and + index aliases used to limit the request. Wildcard expressions (*) are + supported. :arg allow_no_indices: Ignore if a wildcard expression resolves - to no concrete indices (default: false) - :arg expand_wildcards: Whether wildcard expressions should get - expanded to open or closed indices (default: open) Valid choices: open, - closed, hidden, none, all Default: open - :arg flat_settings: Return settings in flat format (default: - false) - :arg ignore_unavailable: Ignore unavailable indexes (default: - false) - :arg include_defaults: Whether to return all default setting for - each of the indices. - :arg include_type_name: Whether to add the type name to the - response (default: false) - :arg local: Return local information, do not retrieve the state - from master node (default: false) - :arg master_timeout: Specify timeout for connection to master + to no concrete indices (default: false) Default: True + :arg expand_wildcards: Type of index that wildcard expressions + can match. If the request can target data streams, this argument + determines whether wildcard expressions match hidden data streams. + Supports comma-separated values, such as open,hidden. Valid choices: + open, closed, hidden, none, all Default: open + :arg flat_settings: If true, returns settings in flat format. + :arg ignore_unavailable: If false, requests that target a + missing index return an error. + :arg include_defaults: If true, return all default settings in + the response. + :arg include_type_name: If true, a mapping type is expected in + the body of mappings. + :arg local: If true, the request retrieves information from the + local node only. Defaults to false, which means information is retrieved + from the master node. + :arg 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. Default: 30s """ if index in SKIP_IN_PATH: raise ValueError("Empty value passed for a required argument 'index'.") @@ -616,7 +633,10 @@ async def delete_alias(self, index, name, params=None, headers=None): raise ValueError("Empty value passed for a required argument.") return await self.transport.perform_request( - "DELETE", _make_path(index, "_alias", name), params=params, headers=headers + "DELETE", + _make_path(index, "_aliases", name), + params=params, + headers=headers, ) @query_params("create", "include_type_name", "master_timeout", "order") @@ -814,9 +834,7 @@ async def stats(self, index=None, metric=None, params=None, headers=None): :arg index: A comma-separated list of index names; use `_all` or empty string to perform the operation on all indices :arg metric: Limit the information returned the specific - metrics. Valid choices: _all, completion, docs, fielddata, query_cache, - flush, get, indexing, merge, request_cache, refresh, search, segments, - store, warmer, suggest + metrics. :arg completion_fields: A comma-separated list of fields for `fielddata` and `suggest` index metric (supports wildcards) :arg expand_wildcards: Whether to expand wildcard expression to diff --git a/elasticsearch/_async/client/indices.pyi b/elasticsearch/_async/client/indices.pyi index b7d0e1861..2c838b029 100644 --- a/elasticsearch/_async/client/indices.pyi +++ b/elasticsearch/_async/client/indices.pyi @@ -19,6 +19,7 @@ from typing import ( Any, Collection, Dict, + List, Mapping, MutableMapping, Optional, @@ -26,6 +27,8 @@ from typing import ( Union, ) +from typing_extensions import Literal + from .utils import NamespacedClient class IndicesClient(NamespacedClient): @@ -50,9 +53,15 @@ class IndicesClient(NamespacedClient): async def refresh( self, *, - index: Optional[Any] = ..., + index: Optional[Union[List[str], str]] = ..., allow_no_indices: Optional[bool] = ..., - expand_wildcards: Optional[Any] = ..., + expand_wildcards: Optional[ + Union[ + List[Union[Literal["all", "open", "closed", "hidden", "none"], str]], + Union[Literal["all", "open", "closed", "hidden", "none"], str], + str, + ] + ] = ..., ignore_unavailable: Optional[bool] = ..., pretty: Optional[bool] = ..., human: Optional[bool] = ..., @@ -70,9 +79,15 @@ class IndicesClient(NamespacedClient): async def flush( self, *, - index: Optional[Any] = ..., + index: Optional[Union[List[str], str]] = ..., allow_no_indices: Optional[bool] = ..., - expand_wildcards: Optional[Any] = ..., + expand_wildcards: Optional[ + Union[ + List[Union[Literal["all", "open", "closed", "hidden", "none"], str]], + Union[Literal["all", "open", "closed", "hidden", "none"], str], + str, + ] + ] = ..., force: Optional[bool] = ..., ignore_unavailable: Optional[bool] = ..., wait_if_ongoing: Optional[bool] = ..., @@ -92,12 +107,17 @@ class IndicesClient(NamespacedClient): async def create( self, *, - index: Any, + index: str, body: Optional[Mapping[str, Any]] = ..., + aliases: Optional[Mapping[str, Mapping[str, Any]]] = ..., include_type_name: Optional[bool] = ..., - master_timeout: Optional[Any] = ..., - timeout: Optional[Any] = ..., - wait_for_active_shards: Optional[Any] = ..., + mappings: Optional[ + Union[Mapping[str, Any], Mapping[str, Mapping[str, Any]]] + ] = ..., + master_timeout: Optional[Union[int, str]] = ..., + settings: Optional[Mapping[str, Any]] = ..., + timeout: Optional[Union[int, str]] = ..., + wait_for_active_shards: Optional[Union[Union[Literal["all"], str], int]] = ..., pretty: Optional[bool] = ..., human: Optional[bool] = ..., error_trace: Optional[bool] = ..., @@ -136,15 +156,21 @@ class IndicesClient(NamespacedClient): async def get( self, *, - index: Any, + index: Union[List[str], str], allow_no_indices: Optional[bool] = ..., - expand_wildcards: Optional[Any] = ..., + expand_wildcards: Optional[ + Union[ + List[Union[Literal["all", "open", "closed", "hidden", "none"], str]], + Union[Literal["all", "open", "closed", "hidden", "none"], str], + str, + ] + ] = ..., flat_settings: Optional[bool] = ..., ignore_unavailable: Optional[bool] = ..., include_defaults: Optional[bool] = ..., include_type_name: Optional[bool] = ..., local: Optional[bool] = ..., - master_timeout: Optional[Any] = ..., + master_timeout: Optional[Union[int, str]] = ..., pretty: Optional[bool] = ..., human: Optional[bool] = ..., error_trace: Optional[bool] = ..., @@ -161,13 +187,19 @@ class IndicesClient(NamespacedClient): async def open( self, *, - index: Any, + index: Union[List[str], str], allow_no_indices: Optional[bool] = ..., - expand_wildcards: Optional[Any] = ..., + expand_wildcards: Optional[ + Union[ + List[Union[Literal["all", "open", "closed", "hidden", "none"], str]], + Union[Literal["all", "open", "closed", "hidden", "none"], str], + str, + ] + ] = ..., ignore_unavailable: Optional[bool] = ..., - master_timeout: Optional[Any] = ..., - timeout: Optional[Any] = ..., - wait_for_active_shards: Optional[Any] = ..., + master_timeout: Optional[Union[int, str]] = ..., + timeout: Optional[Union[int, str]] = ..., + wait_for_active_shards: Optional[Union[Union[Literal["all"], str], int]] = ..., pretty: Optional[bool] = ..., human: Optional[bool] = ..., error_trace: Optional[bool] = ..., @@ -184,13 +216,19 @@ class IndicesClient(NamespacedClient): async def close( self, *, - index: Any, + index: Union[List[str], str], allow_no_indices: Optional[bool] = ..., - expand_wildcards: Optional[Any] = ..., + expand_wildcards: Optional[ + Union[ + List[Union[Literal["all", "open", "closed", "hidden", "none"], str]], + Union[Literal["all", "open", "closed", "hidden", "none"], str], + str, + ] + ] = ..., ignore_unavailable: Optional[bool] = ..., - master_timeout: Optional[Any] = ..., - timeout: Optional[Any] = ..., - wait_for_active_shards: Optional[Any] = ..., + master_timeout: Optional[Union[int, str]] = ..., + timeout: Optional[Union[int, str]] = ..., + wait_for_active_shards: Optional[Union[Union[Literal["all"], str], int]] = ..., pretty: Optional[bool] = ..., human: Optional[bool] = ..., error_trace: Optional[bool] = ..., @@ -207,12 +245,18 @@ class IndicesClient(NamespacedClient): async def delete( self, *, - index: Any, + index: Union[List[str], str], allow_no_indices: Optional[bool] = ..., - expand_wildcards: Optional[Any] = ..., + expand_wildcards: Optional[ + Union[ + List[Union[Literal["all", "open", "closed", "hidden", "none"], str]], + Union[Literal["all", "open", "closed", "hidden", "none"], str], + str, + ] + ] = ..., ignore_unavailable: Optional[bool] = ..., - master_timeout: Optional[Any] = ..., - timeout: Optional[Any] = ..., + master_timeout: Optional[Union[int, str]] = ..., + timeout: Optional[Union[int, str]] = ..., pretty: Optional[bool] = ..., human: Optional[bool] = ..., error_trace: Optional[bool] = ..., @@ -229,9 +273,15 @@ class IndicesClient(NamespacedClient): async def exists( self, *, - index: Any, + index: Union[List[str], str], allow_no_indices: Optional[bool] = ..., - expand_wildcards: Optional[Any] = ..., + expand_wildcards: Optional[ + Union[ + List[Union[Literal["all", "open", "closed", "hidden", "none"], str]], + Union[Literal["all", "open", "closed", "hidden", "none"], str], + str, + ] + ] = ..., flat_settings: Optional[bool] = ..., ignore_unavailable: Optional[bool] = ..., include_defaults: Optional[bool] = ..., @@ -300,14 +350,20 @@ class IndicesClient(NamespacedClient): async def get_mapping( self, *, - index: Optional[Any] = ..., - doc_type: Optional[Any] = ..., + index: Optional[Union[List[str], str]] = ..., + doc_type: Optional[Union[List[str], str]] = ..., allow_no_indices: Optional[bool] = ..., - expand_wildcards: Optional[Any] = ..., + expand_wildcards: Optional[ + Union[ + List[Union[Literal["all", "open", "closed", "hidden", "none"], str]], + Union[Literal["all", "open", "closed", "hidden", "none"], str], + str, + ] + ] = ..., ignore_unavailable: Optional[bool] = ..., include_type_name: Optional[bool] = ..., local: Optional[bool] = ..., - master_timeout: Optional[Any] = ..., + master_timeout: Optional[Union[int, str]] = ..., pretty: Optional[bool] = ..., human: Optional[bool] = ..., error_trace: Optional[bool] = ..., @@ -324,11 +380,17 @@ class IndicesClient(NamespacedClient): async def get_field_mapping( self, *, - fields: Any, - index: Optional[Any] = ..., - doc_type: Optional[Any] = ..., + fields: Union[List[str], str], + index: Optional[Union[List[str], str]] = ..., + doc_type: Optional[Union[List[str], str]] = ..., allow_no_indices: Optional[bool] = ..., - expand_wildcards: Optional[Any] = ..., + expand_wildcards: Optional[ + Union[ + List[Union[Literal["all", "open", "closed", "hidden", "none"], str]], + Union[Literal["all", "open", "closed", "hidden", "none"], str], + str, + ] + ] = ..., ignore_unavailable: Optional[bool] = ..., include_defaults: Optional[bool] = ..., include_type_name: Optional[bool] = ..., @@ -370,10 +432,16 @@ class IndicesClient(NamespacedClient): async def exists_alias( self, *, - name: Any, - index: Optional[Any] = ..., + name: Union[List[str], str], + index: Optional[Union[List[str], str]] = ..., allow_no_indices: Optional[bool] = ..., - expand_wildcards: Optional[Any] = ..., + expand_wildcards: Optional[ + Union[ + List[Union[Literal["all", "open", "closed", "hidden", "none"], str]], + Union[Literal["all", "open", "closed", "hidden", "none"], str], + str, + ] + ] = ..., ignore_unavailable: Optional[bool] = ..., local: Optional[bool] = ..., pretty: Optional[bool] = ..., @@ -392,10 +460,16 @@ class IndicesClient(NamespacedClient): async def get_alias( self, *, - index: Optional[Any] = ..., - name: Optional[Any] = ..., + index: Optional[Union[List[str], str]] = ..., + name: Optional[Union[List[str], str]] = ..., allow_no_indices: Optional[bool] = ..., - expand_wildcards: Optional[Any] = ..., + expand_wildcards: Optional[ + Union[ + List[Union[Literal["all", "open", "closed", "hidden", "none"], str]], + Union[Literal["all", "open", "closed", "hidden", "none"], str], + str, + ] + ] = ..., ignore_unavailable: Optional[bool] = ..., local: Optional[bool] = ..., pretty: Optional[bool] = ..., @@ -433,10 +507,10 @@ class IndicesClient(NamespacedClient): async def delete_alias( self, *, - index: Any, - name: Any, - master_timeout: Optional[Any] = ..., - timeout: Optional[Any] = ..., + index: Union[List[str], str], + name: Union[List[str], str], + master_timeout: Optional[Union[int, str]] = ..., + timeout: Optional[Union[int, str]] = ..., pretty: Optional[bool] = ..., human: Optional[bool] = ..., error_trace: Optional[bool] = ..., @@ -475,10 +549,10 @@ class IndicesClient(NamespacedClient): async def exists_template( self, *, - name: Any, + name: Union[List[str], str], flat_settings: Optional[bool] = ..., local: Optional[bool] = ..., - master_timeout: Optional[Any] = ..., + master_timeout: Optional[Union[int, str]] = ..., pretty: Optional[bool] = ..., human: Optional[bool] = ..., error_trace: Optional[bool] = ..., @@ -495,11 +569,11 @@ class IndicesClient(NamespacedClient): async def get_template( self, *, - name: Optional[Any] = ..., + name: Optional[Union[List[str], str]] = ..., flat_settings: Optional[bool] = ..., include_type_name: Optional[bool] = ..., local: Optional[bool] = ..., - master_timeout: Optional[Any] = ..., + master_timeout: Optional[Union[int, str]] = ..., pretty: Optional[bool] = ..., human: Optional[bool] = ..., error_trace: Optional[bool] = ..., @@ -516,9 +590,9 @@ class IndicesClient(NamespacedClient): async def delete_template( self, *, - name: Any, - master_timeout: Optional[Any] = ..., - timeout: Optional[Any] = ..., + name: str, + master_timeout: Optional[Union[int, str]] = ..., + timeout: Optional[Union[int, str]] = ..., pretty: Optional[bool] = ..., human: Optional[bool] = ..., error_trace: Optional[bool] = ..., @@ -535,15 +609,21 @@ class IndicesClient(NamespacedClient): async def get_settings( self, *, - index: Optional[Any] = ..., - name: Optional[Any] = ..., + index: Optional[Union[List[str], str]] = ..., + name: Optional[Union[List[str], str]] = ..., allow_no_indices: Optional[bool] = ..., - expand_wildcards: Optional[Any] = ..., + expand_wildcards: Optional[ + Union[ + List[Union[Literal["all", "open", "closed", "hidden", "none"], str]], + Union[Literal["all", "open", "closed", "hidden", "none"], str], + str, + ] + ] = ..., flat_settings: Optional[bool] = ..., ignore_unavailable: Optional[bool] = ..., include_defaults: Optional[bool] = ..., local: Optional[bool] = ..., - master_timeout: Optional[Any] = ..., + master_timeout: Optional[Union[int, str]] = ..., pretty: Optional[bool] = ..., human: Optional[bool] = ..., error_trace: Optional[bool] = ..., @@ -585,18 +665,24 @@ class IndicesClient(NamespacedClient): async def stats( self, *, - index: Optional[Any] = ..., - metric: Optional[Any] = ..., - completion_fields: Optional[Any] = ..., - expand_wildcards: Optional[Any] = ..., - fielddata_fields: Optional[Any] = ..., - fields: Optional[Any] = ..., + index: Optional[Union[List[str], str]] = ..., + metric: Optional[Union[List[str], str]] = ..., + completion_fields: Optional[Union[List[str], str]] = ..., + expand_wildcards: Optional[ + Union[ + List[Union[Literal["all", "open", "closed", "hidden", "none"], str]], + Union[Literal["all", "open", "closed", "hidden", "none"], str], + str, + ] + ] = ..., + fielddata_fields: Optional[Union[List[str], str]] = ..., + fields: Optional[Union[List[str], str]] = ..., forbid_closed_indices: Optional[bool] = ..., - groups: Optional[Any] = ..., + groups: Optional[Union[List[str], str]] = ..., include_segment_file_sizes: Optional[bool] = ..., include_unloaded_segments: Optional[bool] = ..., - level: Optional[Any] = ..., - types: Optional[Any] = ..., + level: Optional[Union[Literal["cluster", "indices", "shards"], str]] = ..., + types: Optional[Union[List[str], str]] = ..., pretty: Optional[bool] = ..., human: Optional[bool] = ..., error_trace: Optional[bool] = ..., @@ -613,9 +699,15 @@ class IndicesClient(NamespacedClient): async def segments( self, *, - index: Optional[Any] = ..., + index: Optional[Union[List[str], str]] = ..., allow_no_indices: Optional[bool] = ..., - expand_wildcards: Optional[Any] = ..., + expand_wildcards: Optional[ + Union[ + List[Union[Literal["all", "open", "closed", "hidden", "none"], str]], + Union[Literal["all", "open", "closed", "hidden", "none"], str], + str, + ] + ] = ..., ignore_unavailable: Optional[bool] = ..., verbose: Optional[bool] = ..., pretty: Optional[bool] = ..., @@ -770,11 +862,17 @@ class IndicesClient(NamespacedClient): async def shard_stores( self, *, - index: Optional[Any] = ..., + index: Optional[Union[List[str], str]] = ..., allow_no_indices: Optional[bool] = ..., - expand_wildcards: Optional[Any] = ..., + expand_wildcards: Optional[ + Union[ + List[Union[Literal["all", "open", "closed", "hidden", "none"], str]], + Union[Literal["all", "open", "closed", "hidden", "none"], str], + str, + ] + ] = ..., ignore_unavailable: Optional[bool] = ..., - status: Optional[Any] = ..., + status: Optional[Union[List[str], str]] = ..., pretty: Optional[bool] = ..., human: Optional[bool] = ..., error_trace: Optional[bool] = ..., @@ -950,7 +1048,7 @@ class IndicesClient(NamespacedClient): async def create_data_stream( self, *, - name: Any, + name: str, pretty: Optional[bool] = ..., human: Optional[bool] = ..., error_trace: Optional[bool] = ..., @@ -967,8 +1065,14 @@ class IndicesClient(NamespacedClient): async def delete_data_stream( self, *, - name: Any, - expand_wildcards: Optional[Any] = ..., + name: Union[List[str], str], + expand_wildcards: Optional[ + Union[ + List[Union[Literal["all", "open", "closed", "hidden", "none"], str]], + Union[Literal["all", "open", "closed", "hidden", "none"], str], + str, + ] + ] = ..., pretty: Optional[bool] = ..., human: Optional[bool] = ..., error_trace: Optional[bool] = ..., @@ -1086,8 +1190,14 @@ class IndicesClient(NamespacedClient): async def get_data_stream( self, *, - name: Optional[Any] = ..., - expand_wildcards: Optional[Any] = ..., + name: Optional[Union[List[str], str]] = ..., + expand_wildcards: Optional[ + Union[ + List[Union[Literal["all", "open", "closed", "hidden", "none"], str]], + Union[Literal["all", "open", "closed", "hidden", "none"], str], + str, + ] + ] = ..., pretty: Optional[bool] = ..., human: Optional[bool] = ..., error_trace: Optional[bool] = ..., diff --git a/elasticsearch/_async/client/ml.py b/elasticsearch/_async/client/ml.py index 6d639a00f..151c90e93 100644 --- a/elasticsearch/_async/client/ml.py +++ b/elasticsearch/_async/client/ml.py @@ -1514,7 +1514,7 @@ async def get_trained_models_stats(self, model_id=None, params=None, headers=Non headers=headers, ) - @query_params() + @query_params("defer_definition_decompression") async def put_trained_model(self, model_id, body, params=None, headers=None): """ Creates an inference trained model. @@ -1523,6 +1523,9 @@ async def put_trained_model(self, model_id, body, params=None, headers=None): :arg model_id: The ID of the trained models to store :arg body: The trained model configuration + :arg defer_definition_decompression: If set to `true` and a + `compressed_definition` is provided, the request defers definition + decompression and skips relevant validations. """ for param in (model_id, body): if param in SKIP_IN_PATH: diff --git a/elasticsearch/_async/client/ml.pyi b/elasticsearch/_async/client/ml.pyi index 2d50e56c2..bb3b9654e 100644 --- a/elasticsearch/_async/client/ml.pyi +++ b/elasticsearch/_async/client/ml.pyi @@ -1152,6 +1152,7 @@ class MlClient(NamespacedClient): *, model_id: Any, body: Mapping[str, Any], + defer_definition_decompression: Optional[bool] = ..., pretty: Optional[bool] = ..., human: Optional[bool] = ..., error_trace: Optional[bool] = ..., diff --git a/elasticsearch/client/__init__.py b/elasticsearch/client/__init__.py index 980e11f5a..5483a25ad 100644 --- a/elasticsearch/client/__init__.py +++ b/elasticsearch/client/__init__.py @@ -1002,9 +1002,9 @@ def get(self, index, id, doc_type=None, params=None, headers=None): to include in the response. :arg preference: Specifies the node or shard the operation should be performed on. Random by default. - :arg realtime: Boolean) If true, the request is real-time as + :arg realtime: Boolean) If true, the request is real-time as opposed to near-real-time. Default: True - :arg refresh: If true, Elasticsearch refreshes the affected + :arg refresh: If true, Elasticsearch refreshes the affected shards to make this operation visible to search. If false, do nothing with refreshes. :arg routing: Target the specified primary shard. @@ -1602,8 +1602,8 @@ def search(self, body=None, index=None, doc_type=None, params=None, headers=None :arg doc_type: A comma-separated list of document types to search; leave empty to perform the operation on all types :arg _source: Indicates which source fields are returned for - matching documents. These fields are returned in the hits._source - property of the search response. + matching documents. These + fields are returned in the hits._source property of the search response. :arg _source_excludes: A list of fields to exclude from the returned _source field :arg _source_includes: A list of fields to extract and return @@ -1633,19 +1633,22 @@ def search(self, body=None, index=None, doc_type=None, params=None, headers=None :arg df: The field to use as default where no field prefix is given in the query string :arg docvalue_fields: Array of wildcard (*) patterns. The - request returns doc values for field names matching these patterns in - the hits.fields property of the response. + request returns doc values for field + names matching these patterns in the hits.fields property of the + response. :arg expand_wildcards: Whether to expand wildcard expression to concrete indices that are open, closed or both. Valid choices: open, closed, hidden, none, all Default: open :arg explain: If true, returns detailed information about score computation as part of a hit. :arg fields: Array of wildcard (*) patterns. The request returns - values for field names matching these patterns in the hits.fields - property of the response. + values for field names + matching these patterns in the hits.fields property of the response. :arg from_: Starting document offset. By default, you cannot - page through more than 10,000 hits using the from and size parameters. - To page through more hits, use the search_after parameter. + page through more than 10,000 + hits using the from and size parameters. To page through more hits, use + the + search_after parameter. :arg highlight: :arg ignore_throttled: Whether specified concrete, expanded or aliased indices should be ignored when throttled @@ -1663,13 +1666,15 @@ def search(self, body=None, index=None, doc_type=None, params=None, headers=None that all shards involved in search should have for this request to be successful :arg min_score: Minimum _score for matching documents. Documents - with a lower _score are not included in the search results. + with a lower _score are + not included in the search results. :arg pit: Limits the search to a point in time (PIT). If you - provide a PIT, you cannot specify an in the request path. + provide a PIT, you + cannot specify an in the request path. :arg post_filter: :arg pre_filter_shard_size: A threshold that enforces a pre- filter roundtrip to prefilter search shards based on query rewriting if - the number of shards the search request expands to exceeds the + the number of shards the search request expands to exceeds the threshold. This filter roundtrip can limit the number of shards significantly if for instance a shard can not match any documents based on its rewrite method ie. if date filters are mandatory to match but the @@ -1686,8 +1691,8 @@ def search(self, body=None, index=None, doc_type=None, params=None, headers=None be rendered as an integer or an object in the rest search response :arg routing: A comma-separated list of specific routing values :arg runtime_mappings: Defines one or more runtime fields in the - search request. These fields take precedence over mapped fields with the - same name. + search request. These fields take + precedence over mapped fields with the same name. :arg script_fields: Retrieve a script evaluation (based on different fields) for each hit. :arg scroll: Specify how long a consistent view of the index @@ -1696,21 +1701,27 @@ def search(self, body=None, index=None, doc_type=None, params=None, headers=None :arg search_type: Search operation type Valid choices: query_then_fetch, dfs_query_then_fetch :arg seq_no_primary_term: If true, returns sequence number and - primary term of the last modification of each hit. See Optimistic - concurrency control. + primary term of the last modification + of each hit. See Optimistic concurrency control. :arg size: The number of hits to return. By default, you cannot - page through more than 10,000 hits using the from and size parameters. - To page through more hits, use the search_after parameter. + page through more + than 10,000 hits using the from and size parameters. To page through + more + hits, use the search_after parameter. :arg slice: :arg sort: :arg stats: Stats groups to associate with the search. Each - group maintains a statistics aggregation for its associated searches. - You can retrieve these stats using the indices stats API. + group maintains a statistics + aggregation for its associated searches. You can retrieve these stats + using + the indices stats API. :arg stored_fields: List of stored fields to return as part of a - hit. If no fields are specified, no stored fields are included in the - response. If this field is specified, the _source parameter defaults to - false. You can pass _source: true to return both source fields and - stored fields in the search response. + hit. If no fields are specified, + no stored fields are included in the response. If this field is + specified, the _source + parameter defaults to false. You can pass _source: true to return both + source fields + and stored fields in the search response. :arg suggest: :arg suggest_field: Specifies which field to use for suggestions. @@ -1720,18 +1731,24 @@ def search(self, body=None, index=None, doc_type=None, params=None, headers=None :arg suggest_text: The source text for which the suggestions should be returned. :arg terminate_after: Maximum number of documents to collect for - each shard. If a query reaches this limit, Elasticsearch terminates the - query early. Elasticsearch collects documents before sorting. Defaults - to 0, which does not terminate query execution early. + each shard. If a query reaches this + limit, Elasticsearch terminates the query early. Elasticsearch collects + documents + before sorting. Defaults to 0, which does not terminate query execution + early. :arg timeout: Specifies the period of time to wait for a - response from each shard. If no response is received before the timeout - expires, the request fails and returns an error. Defaults to no timeout. + response from each shard. If no response + is received before the timeout expires, the request fails and returns an + error. + Defaults to no timeout. :arg track_scores: If true, calculate and return document scores, even if the scores are not used for sorting. :arg track_total_hits: Number of hits matching the query to - count accurately. If true, the exact number of hits is returned at the - cost of some performance. If false, the response does not include the - total number of hits matching the query. Defaults to 10,000 hits. + count accurately. If true, the exact + number of hits is returned at the cost of some performance. If false, + the + response does not include the total number of hits matching the query. + Defaults to 10,000 hits. :arg typed_keys: Specify whether aggregation and suggester names should be prefixed by their respective types in the response :arg version: If true, returns document version as part of a @@ -1933,6 +1950,7 @@ def termvectors( "scripted_upsert", "upsert", ], + body_required=True, ) def update(self, index, id, body, doc_type=None, params=None, headers=None): """ @@ -1946,13 +1964,15 @@ def update(self, index, id, body, doc_type=None, params=None, headers=None): partial `doc` :arg doc_type: The type of the document :arg _source: Set to false to disable source retrieval. You can - also specify a comma-separated list of the fields you want to retrieve. + also specify a comma-separated + list of the fields you want to retrieve. :arg _source_excludes: Specify the source fields you want to exclude. :arg _source_includes: Specify the source fields you want to retrieve. :arg detect_noop: Set to false to disable setting 'result' in - the response to 'noop' if no change to the document occurred. + the response + to 'noop' if no change to the document occurred. :arg doc: A partial update to an existing document. :arg doc_as_upsert: Set to true to use the contents of 'doc' as the value of 'upsert' @@ -1962,10 +1982,11 @@ def update(self, index, id, body, doc_type=None, params=None, headers=None): this sequence number. :arg lang: The script language. Default: painless :arg refresh: If 'true', Elasticsearch refreshes the affected - shards to make this operation visible to search, if 'wait_for' then wait - for a refresh to make this operation visible to search, if 'false' do - nothing with refreshes. Valid choices: true, false, wait_for Default: - false + shards to make this operation + visible to search, if 'wait_for' then wait for a refresh to make this + operation + visible to search, if 'false' do nothing with refreshes. Valid choices: + true, false, wait_for Default: false :arg require_alias: If true, the destination must be an index alias. :arg retry_on_conflict: Specify how many times should the @@ -1976,15 +1997,18 @@ def update(self, index, id, body, doc_type=None, params=None, headers=None): :arg scripted_upsert: Set to true to execute the script whether or not the document exists. :arg timeout: Period to wait for dynamic mapping updates and - active shards. This guarantees Elasticsearch waits for at least the - timeout before failing. The actual wait time could be longer, - particularly when multiple waits occur. Default: 1m + active shards. + This guarantees Elasticsearch waits for at least the timeout before + failing. + The actual wait time could be longer, particularly when multiple waits + occur. Default: 1m :arg upsert: If the document does not already exist, the - contents of 'upsert' are inserted as a new document. If the document - exists, the 'script' is executed. + contents of 'upsert' are inserted as a + new document. If the document exists, the 'script' is executed. :arg wait_for_active_shards: The number of shard copies that - must be active before proceeding with the operations. Set to 'all' or - any positive integer up to the total number of shards in the index + must be active before proceeding with the operations. + Set to 'all' or any positive integer up to the total number of shards in + the index (number_of_replicas+1). Defaults to 1 meaning the primary shard. Default: 1 """ diff --git a/elasticsearch/client/__init__.pyi b/elasticsearch/client/__init__.pyi index 097c84b1a..1b9836219 100644 --- a/elasticsearch/client/__init__.pyi +++ b/elasticsearch/client/__init__.pyi @@ -440,7 +440,7 @@ class Elasticsearch(object): api_key: Optional[Union[str, Tuple[str, str]]] = ..., params: Optional[MutableMapping[str, Any]] = ..., headers: Optional[MutableMapping[str, str]] = ..., - ) -> Any: ... + ) -> bool: ... def exists_source( self, *, diff --git a/elasticsearch/client/indices.py b/elasticsearch/client/indices.py index bd9032a09..1f09da3db 100644 --- a/elasticsearch/client/indices.py +++ b/elasticsearch/client/indices.py @@ -99,7 +99,11 @@ def flush(self, index=None, params=None, headers=None): ) @query_params( - "include_type_name", "master_timeout", "timeout", "wait_for_active_shards" + "include_type_name", + "master_timeout", + "timeout", + "wait_for_active_shards", + body_params=["aliases", "mappings", "settings"], ) def create(self, index, body=None, params=None, headers=None): """ @@ -110,9 +114,16 @@ def create(self, index, body=None, params=None, headers=None): :arg index: The name of the index :arg body: The configuration for the index (`settings` and `mappings`) + :arg aliases: :arg include_type_name: Whether a type should be expected in the body of the mappings. + :arg mappings: Mapping for fields in the index. If specified, + this mapping can include: + - Field names + - Field data types + - Mapping parameters :arg master_timeout: Specify timeout for connection to master + :arg settings: :arg timeout: Explicit operation timeout :arg wait_for_active_shards: Set the number of active shards to wait for before the operation returns. @@ -168,23 +179,29 @@ def get(self, index, params=None, headers=None): ``_ - :arg index: A comma-separated list of index names + :arg index: Comma-separated list of data streams, indices, and + index aliases used to limit the request. Wildcard expressions (*) are + supported. :arg allow_no_indices: Ignore if a wildcard expression resolves - to no concrete indices (default: false) - :arg expand_wildcards: Whether wildcard expressions should get - expanded to open or closed indices (default: open) Valid choices: open, - closed, hidden, none, all Default: open - :arg flat_settings: Return settings in flat format (default: - false) - :arg ignore_unavailable: Ignore unavailable indexes (default: - false) - :arg include_defaults: Whether to return all default setting for - each of the indices. - :arg include_type_name: Whether to add the type name to the - response (default: false) - :arg local: Return local information, do not retrieve the state - from master node (default: false) - :arg master_timeout: Specify timeout for connection to master + to no concrete indices (default: false) Default: True + :arg expand_wildcards: Type of index that wildcard expressions + can match. If the request can target data streams, this argument + determines whether wildcard expressions match hidden data streams. + Supports comma-separated values, such as open,hidden. Valid choices: + open, closed, hidden, none, all Default: open + :arg flat_settings: If true, returns settings in flat format. + :arg ignore_unavailable: If false, requests that target a + missing index return an error. + :arg include_defaults: If true, return all default settings in + the response. + :arg include_type_name: If true, a mapping type is expected in + the body of mappings. + :arg local: If true, the request retrieves information from the + local node only. Defaults to false, which means information is retrieved + from the master node. + :arg 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. Default: 30s """ if index in SKIP_IN_PATH: raise ValueError("Empty value passed for a required argument 'index'.") @@ -614,7 +631,10 @@ def delete_alias(self, index, name, params=None, headers=None): raise ValueError("Empty value passed for a required argument.") return self.transport.perform_request( - "DELETE", _make_path(index, "_alias", name), params=params, headers=headers + "DELETE", + _make_path(index, "_aliases", name), + params=params, + headers=headers, ) @query_params("create", "include_type_name", "master_timeout", "order") @@ -812,9 +832,7 @@ def stats(self, index=None, metric=None, params=None, headers=None): :arg index: A comma-separated list of index names; use `_all` or empty string to perform the operation on all indices :arg metric: Limit the information returned the specific - metrics. Valid choices: _all, completion, docs, fielddata, query_cache, - flush, get, indexing, merge, request_cache, refresh, search, segments, - store, warmer, suggest + metrics. :arg completion_fields: A comma-separated list of fields for `fielddata` and `suggest` index metric (supports wildcards) :arg expand_wildcards: Whether to expand wildcard expression to diff --git a/elasticsearch/client/indices.pyi b/elasticsearch/client/indices.pyi index eef8d2ec1..448353816 100644 --- a/elasticsearch/client/indices.pyi +++ b/elasticsearch/client/indices.pyi @@ -19,6 +19,7 @@ from typing import ( Any, Collection, Dict, + List, Mapping, MutableMapping, Optional, @@ -26,6 +27,8 @@ from typing import ( Union, ) +from typing_extensions import Literal + from .utils import NamespacedClient class IndicesClient(NamespacedClient): @@ -50,9 +53,15 @@ class IndicesClient(NamespacedClient): def refresh( self, *, - index: Optional[Any] = ..., + index: Optional[Union[List[str], str]] = ..., allow_no_indices: Optional[bool] = ..., - expand_wildcards: Optional[Any] = ..., + expand_wildcards: Optional[ + Union[ + List[Union[Literal["all", "open", "closed", "hidden", "none"], str]], + Union[Literal["all", "open", "closed", "hidden", "none"], str], + str, + ] + ] = ..., ignore_unavailable: Optional[bool] = ..., pretty: Optional[bool] = ..., human: Optional[bool] = ..., @@ -70,9 +79,15 @@ class IndicesClient(NamespacedClient): def flush( self, *, - index: Optional[Any] = ..., + index: Optional[Union[List[str], str]] = ..., allow_no_indices: Optional[bool] = ..., - expand_wildcards: Optional[Any] = ..., + expand_wildcards: Optional[ + Union[ + List[Union[Literal["all", "open", "closed", "hidden", "none"], str]], + Union[Literal["all", "open", "closed", "hidden", "none"], str], + str, + ] + ] = ..., force: Optional[bool] = ..., ignore_unavailable: Optional[bool] = ..., wait_if_ongoing: Optional[bool] = ..., @@ -92,12 +107,17 @@ class IndicesClient(NamespacedClient): def create( self, *, - index: Any, + index: str, body: Optional[Mapping[str, Any]] = ..., + aliases: Optional[Mapping[str, Mapping[str, Any]]] = ..., include_type_name: Optional[bool] = ..., - master_timeout: Optional[Any] = ..., - timeout: Optional[Any] = ..., - wait_for_active_shards: Optional[Any] = ..., + mappings: Optional[ + Union[Mapping[str, Any], Mapping[str, Mapping[str, Any]]] + ] = ..., + master_timeout: Optional[Union[int, str]] = ..., + settings: Optional[Mapping[str, Any]] = ..., + timeout: Optional[Union[int, str]] = ..., + wait_for_active_shards: Optional[Union[Union[Literal["all"], str], int]] = ..., pretty: Optional[bool] = ..., human: Optional[bool] = ..., error_trace: Optional[bool] = ..., @@ -136,15 +156,21 @@ class IndicesClient(NamespacedClient): def get( self, *, - index: Any, + index: Union[List[str], str], allow_no_indices: Optional[bool] = ..., - expand_wildcards: Optional[Any] = ..., + expand_wildcards: Optional[ + Union[ + List[Union[Literal["all", "open", "closed", "hidden", "none"], str]], + Union[Literal["all", "open", "closed", "hidden", "none"], str], + str, + ] + ] = ..., flat_settings: Optional[bool] = ..., ignore_unavailable: Optional[bool] = ..., include_defaults: Optional[bool] = ..., include_type_name: Optional[bool] = ..., local: Optional[bool] = ..., - master_timeout: Optional[Any] = ..., + master_timeout: Optional[Union[int, str]] = ..., pretty: Optional[bool] = ..., human: Optional[bool] = ..., error_trace: Optional[bool] = ..., @@ -161,13 +187,19 @@ class IndicesClient(NamespacedClient): def open( self, *, - index: Any, + index: Union[List[str], str], allow_no_indices: Optional[bool] = ..., - expand_wildcards: Optional[Any] = ..., + expand_wildcards: Optional[ + Union[ + List[Union[Literal["all", "open", "closed", "hidden", "none"], str]], + Union[Literal["all", "open", "closed", "hidden", "none"], str], + str, + ] + ] = ..., ignore_unavailable: Optional[bool] = ..., - master_timeout: Optional[Any] = ..., - timeout: Optional[Any] = ..., - wait_for_active_shards: Optional[Any] = ..., + master_timeout: Optional[Union[int, str]] = ..., + timeout: Optional[Union[int, str]] = ..., + wait_for_active_shards: Optional[Union[Union[Literal["all"], str], int]] = ..., pretty: Optional[bool] = ..., human: Optional[bool] = ..., error_trace: Optional[bool] = ..., @@ -184,13 +216,19 @@ class IndicesClient(NamespacedClient): def close( self, *, - index: Any, + index: Union[List[str], str], allow_no_indices: Optional[bool] = ..., - expand_wildcards: Optional[Any] = ..., + expand_wildcards: Optional[ + Union[ + List[Union[Literal["all", "open", "closed", "hidden", "none"], str]], + Union[Literal["all", "open", "closed", "hidden", "none"], str], + str, + ] + ] = ..., ignore_unavailable: Optional[bool] = ..., - master_timeout: Optional[Any] = ..., - timeout: Optional[Any] = ..., - wait_for_active_shards: Optional[Any] = ..., + master_timeout: Optional[Union[int, str]] = ..., + timeout: Optional[Union[int, str]] = ..., + wait_for_active_shards: Optional[Union[Union[Literal["all"], str], int]] = ..., pretty: Optional[bool] = ..., human: Optional[bool] = ..., error_trace: Optional[bool] = ..., @@ -207,12 +245,18 @@ class IndicesClient(NamespacedClient): def delete( self, *, - index: Any, + index: Union[List[str], str], allow_no_indices: Optional[bool] = ..., - expand_wildcards: Optional[Any] = ..., + expand_wildcards: Optional[ + Union[ + List[Union[Literal["all", "open", "closed", "hidden", "none"], str]], + Union[Literal["all", "open", "closed", "hidden", "none"], str], + str, + ] + ] = ..., ignore_unavailable: Optional[bool] = ..., - master_timeout: Optional[Any] = ..., - timeout: Optional[Any] = ..., + master_timeout: Optional[Union[int, str]] = ..., + timeout: Optional[Union[int, str]] = ..., pretty: Optional[bool] = ..., human: Optional[bool] = ..., error_trace: Optional[bool] = ..., @@ -229,9 +273,15 @@ class IndicesClient(NamespacedClient): def exists( self, *, - index: Any, + index: Union[List[str], str], allow_no_indices: Optional[bool] = ..., - expand_wildcards: Optional[Any] = ..., + expand_wildcards: Optional[ + Union[ + List[Union[Literal["all", "open", "closed", "hidden", "none"], str]], + Union[Literal["all", "open", "closed", "hidden", "none"], str], + str, + ] + ] = ..., flat_settings: Optional[bool] = ..., ignore_unavailable: Optional[bool] = ..., include_defaults: Optional[bool] = ..., @@ -300,14 +350,20 @@ class IndicesClient(NamespacedClient): def get_mapping( self, *, - index: Optional[Any] = ..., - doc_type: Optional[Any] = ..., + index: Optional[Union[List[str], str]] = ..., + doc_type: Optional[Union[List[str], str]] = ..., allow_no_indices: Optional[bool] = ..., - expand_wildcards: Optional[Any] = ..., + expand_wildcards: Optional[ + Union[ + List[Union[Literal["all", "open", "closed", "hidden", "none"], str]], + Union[Literal["all", "open", "closed", "hidden", "none"], str], + str, + ] + ] = ..., ignore_unavailable: Optional[bool] = ..., include_type_name: Optional[bool] = ..., local: Optional[bool] = ..., - master_timeout: Optional[Any] = ..., + master_timeout: Optional[Union[int, str]] = ..., pretty: Optional[bool] = ..., human: Optional[bool] = ..., error_trace: Optional[bool] = ..., @@ -324,11 +380,17 @@ class IndicesClient(NamespacedClient): def get_field_mapping( self, *, - fields: Any, - index: Optional[Any] = ..., - doc_type: Optional[Any] = ..., + fields: Union[List[str], str], + index: Optional[Union[List[str], str]] = ..., + doc_type: Optional[Union[List[str], str]] = ..., allow_no_indices: Optional[bool] = ..., - expand_wildcards: Optional[Any] = ..., + expand_wildcards: Optional[ + Union[ + List[Union[Literal["all", "open", "closed", "hidden", "none"], str]], + Union[Literal["all", "open", "closed", "hidden", "none"], str], + str, + ] + ] = ..., ignore_unavailable: Optional[bool] = ..., include_defaults: Optional[bool] = ..., include_type_name: Optional[bool] = ..., @@ -370,10 +432,16 @@ class IndicesClient(NamespacedClient): def exists_alias( self, *, - name: Any, - index: Optional[Any] = ..., + name: Union[List[str], str], + index: Optional[Union[List[str], str]] = ..., allow_no_indices: Optional[bool] = ..., - expand_wildcards: Optional[Any] = ..., + expand_wildcards: Optional[ + Union[ + List[Union[Literal["all", "open", "closed", "hidden", "none"], str]], + Union[Literal["all", "open", "closed", "hidden", "none"], str], + str, + ] + ] = ..., ignore_unavailable: Optional[bool] = ..., local: Optional[bool] = ..., pretty: Optional[bool] = ..., @@ -392,10 +460,16 @@ class IndicesClient(NamespacedClient): def get_alias( self, *, - index: Optional[Any] = ..., - name: Optional[Any] = ..., + index: Optional[Union[List[str], str]] = ..., + name: Optional[Union[List[str], str]] = ..., allow_no_indices: Optional[bool] = ..., - expand_wildcards: Optional[Any] = ..., + expand_wildcards: Optional[ + Union[ + List[Union[Literal["all", "open", "closed", "hidden", "none"], str]], + Union[Literal["all", "open", "closed", "hidden", "none"], str], + str, + ] + ] = ..., ignore_unavailable: Optional[bool] = ..., local: Optional[bool] = ..., pretty: Optional[bool] = ..., @@ -433,10 +507,10 @@ class IndicesClient(NamespacedClient): def delete_alias( self, *, - index: Any, - name: Any, - master_timeout: Optional[Any] = ..., - timeout: Optional[Any] = ..., + index: Union[List[str], str], + name: Union[List[str], str], + master_timeout: Optional[Union[int, str]] = ..., + timeout: Optional[Union[int, str]] = ..., pretty: Optional[bool] = ..., human: Optional[bool] = ..., error_trace: Optional[bool] = ..., @@ -475,10 +549,10 @@ class IndicesClient(NamespacedClient): def exists_template( self, *, - name: Any, + name: Union[List[str], str], flat_settings: Optional[bool] = ..., local: Optional[bool] = ..., - master_timeout: Optional[Any] = ..., + master_timeout: Optional[Union[int, str]] = ..., pretty: Optional[bool] = ..., human: Optional[bool] = ..., error_trace: Optional[bool] = ..., @@ -495,11 +569,11 @@ class IndicesClient(NamespacedClient): def get_template( self, *, - name: Optional[Any] = ..., + name: Optional[Union[List[str], str]] = ..., flat_settings: Optional[bool] = ..., include_type_name: Optional[bool] = ..., local: Optional[bool] = ..., - master_timeout: Optional[Any] = ..., + master_timeout: Optional[Union[int, str]] = ..., pretty: Optional[bool] = ..., human: Optional[bool] = ..., error_trace: Optional[bool] = ..., @@ -516,9 +590,9 @@ class IndicesClient(NamespacedClient): def delete_template( self, *, - name: Any, - master_timeout: Optional[Any] = ..., - timeout: Optional[Any] = ..., + name: str, + master_timeout: Optional[Union[int, str]] = ..., + timeout: Optional[Union[int, str]] = ..., pretty: Optional[bool] = ..., human: Optional[bool] = ..., error_trace: Optional[bool] = ..., @@ -535,15 +609,21 @@ class IndicesClient(NamespacedClient): def get_settings( self, *, - index: Optional[Any] = ..., - name: Optional[Any] = ..., + index: Optional[Union[List[str], str]] = ..., + name: Optional[Union[List[str], str]] = ..., allow_no_indices: Optional[bool] = ..., - expand_wildcards: Optional[Any] = ..., + expand_wildcards: Optional[ + Union[ + List[Union[Literal["all", "open", "closed", "hidden", "none"], str]], + Union[Literal["all", "open", "closed", "hidden", "none"], str], + str, + ] + ] = ..., flat_settings: Optional[bool] = ..., ignore_unavailable: Optional[bool] = ..., include_defaults: Optional[bool] = ..., local: Optional[bool] = ..., - master_timeout: Optional[Any] = ..., + master_timeout: Optional[Union[int, str]] = ..., pretty: Optional[bool] = ..., human: Optional[bool] = ..., error_trace: Optional[bool] = ..., @@ -585,18 +665,24 @@ class IndicesClient(NamespacedClient): def stats( self, *, - index: Optional[Any] = ..., - metric: Optional[Any] = ..., - completion_fields: Optional[Any] = ..., - expand_wildcards: Optional[Any] = ..., - fielddata_fields: Optional[Any] = ..., - fields: Optional[Any] = ..., + index: Optional[Union[List[str], str]] = ..., + metric: Optional[Union[List[str], str]] = ..., + completion_fields: Optional[Union[List[str], str]] = ..., + expand_wildcards: Optional[ + Union[ + List[Union[Literal["all", "open", "closed", "hidden", "none"], str]], + Union[Literal["all", "open", "closed", "hidden", "none"], str], + str, + ] + ] = ..., + fielddata_fields: Optional[Union[List[str], str]] = ..., + fields: Optional[Union[List[str], str]] = ..., forbid_closed_indices: Optional[bool] = ..., - groups: Optional[Any] = ..., + groups: Optional[Union[List[str], str]] = ..., include_segment_file_sizes: Optional[bool] = ..., include_unloaded_segments: Optional[bool] = ..., - level: Optional[Any] = ..., - types: Optional[Any] = ..., + level: Optional[Union[Literal["cluster", "indices", "shards"], str]] = ..., + types: Optional[Union[List[str], str]] = ..., pretty: Optional[bool] = ..., human: Optional[bool] = ..., error_trace: Optional[bool] = ..., @@ -613,9 +699,15 @@ class IndicesClient(NamespacedClient): def segments( self, *, - index: Optional[Any] = ..., + index: Optional[Union[List[str], str]] = ..., allow_no_indices: Optional[bool] = ..., - expand_wildcards: Optional[Any] = ..., + expand_wildcards: Optional[ + Union[ + List[Union[Literal["all", "open", "closed", "hidden", "none"], str]], + Union[Literal["all", "open", "closed", "hidden", "none"], str], + str, + ] + ] = ..., ignore_unavailable: Optional[bool] = ..., verbose: Optional[bool] = ..., pretty: Optional[bool] = ..., @@ -770,11 +862,17 @@ class IndicesClient(NamespacedClient): def shard_stores( self, *, - index: Optional[Any] = ..., + index: Optional[Union[List[str], str]] = ..., allow_no_indices: Optional[bool] = ..., - expand_wildcards: Optional[Any] = ..., + expand_wildcards: Optional[ + Union[ + List[Union[Literal["all", "open", "closed", "hidden", "none"], str]], + Union[Literal["all", "open", "closed", "hidden", "none"], str], + str, + ] + ] = ..., ignore_unavailable: Optional[bool] = ..., - status: Optional[Any] = ..., + status: Optional[Union[List[str], str]] = ..., pretty: Optional[bool] = ..., human: Optional[bool] = ..., error_trace: Optional[bool] = ..., @@ -950,7 +1048,7 @@ class IndicesClient(NamespacedClient): def create_data_stream( self, *, - name: Any, + name: str, pretty: Optional[bool] = ..., human: Optional[bool] = ..., error_trace: Optional[bool] = ..., @@ -967,8 +1065,14 @@ class IndicesClient(NamespacedClient): def delete_data_stream( self, *, - name: Any, - expand_wildcards: Optional[Any] = ..., + name: Union[List[str], str], + expand_wildcards: Optional[ + Union[ + List[Union[Literal["all", "open", "closed", "hidden", "none"], str]], + Union[Literal["all", "open", "closed", "hidden", "none"], str], + str, + ] + ] = ..., pretty: Optional[bool] = ..., human: Optional[bool] = ..., error_trace: Optional[bool] = ..., @@ -1086,8 +1190,14 @@ class IndicesClient(NamespacedClient): def get_data_stream( self, *, - name: Optional[Any] = ..., - expand_wildcards: Optional[Any] = ..., + name: Optional[Union[List[str], str]] = ..., + expand_wildcards: Optional[ + Union[ + List[Union[Literal["all", "open", "closed", "hidden", "none"], str]], + Union[Literal["all", "open", "closed", "hidden", "none"], str], + str, + ] + ] = ..., pretty: Optional[bool] = ..., human: Optional[bool] = ..., error_trace: Optional[bool] = ..., diff --git a/elasticsearch/client/ml.py b/elasticsearch/client/ml.py index 683de070b..2ac02ebbc 100644 --- a/elasticsearch/client/ml.py +++ b/elasticsearch/client/ml.py @@ -1498,7 +1498,7 @@ def get_trained_models_stats(self, model_id=None, params=None, headers=None): headers=headers, ) - @query_params() + @query_params("defer_definition_decompression") def put_trained_model(self, model_id, body, params=None, headers=None): """ Creates an inference trained model. @@ -1507,6 +1507,9 @@ def put_trained_model(self, model_id, body, params=None, headers=None): :arg model_id: The ID of the trained models to store :arg body: The trained model configuration + :arg defer_definition_decompression: If set to `true` and a + `compressed_definition` is provided, the request defers definition + decompression and skips relevant validations. """ for param in (model_id, body): if param in SKIP_IN_PATH: diff --git a/elasticsearch/client/ml.pyi b/elasticsearch/client/ml.pyi index ff947f191..43621ef94 100644 --- a/elasticsearch/client/ml.pyi +++ b/elasticsearch/client/ml.pyi @@ -1152,6 +1152,7 @@ class MlClient(NamespacedClient): *, model_id: Any, body: Mapping[str, Any], + defer_definition_decompression: Optional[bool] = ..., pretty: Optional[bool] = ..., human: Optional[bool] = ..., error_trace: Optional[bool] = ..., diff --git a/elasticsearch/client/utils.py b/elasticsearch/client/utils.py index fda131a57..cd7b138b8 100644 --- a/elasticsearch/client/utils.py +++ b/elasticsearch/client/utils.py @@ -132,10 +132,15 @@ def query_params(*es_query_params, **kwargs): body_params = kwargs.pop("body_params", None) body_only_params = set(body_params or ()) - set(es_query_params) body_name = kwargs.pop("body_name", None) + body_required = kwargs.pop("body_required", False) # There should be no APIs defined with both 'body_params' and a named body. assert not (body_name and body_params) + # 'body_required' implies there's no named body and that body_params are defined. + assert not (body_name and body_required) + assert not body_required or body_params + def _wrapper(func): @wraps(func) def _wrapped(*args, **kwargs): @@ -213,6 +218,12 @@ def _wrapped(*args, **kwargs): body[param.rstrip("_")] = value kwargs["body"] = body + # Since we've deprecated 'body' we set body={} if there + # should be a body on JSON-field APIs but none of those fields + # are filled. + elif body_required: + kwargs["body"] = {} + # If there's a named body parameter then we transform it to 'body' # for backwards compatibility with libraries like APM. # Otherwise we warn the user about 'body' being deprecated. diff --git a/elasticsearch/client/utils.pyi b/elasticsearch/client/utils.pyi index 9bc752297..ef0b8bdb9 100644 --- a/elasticsearch/client/utils.pyi +++ b/elasticsearch/client/utils.pyi @@ -49,7 +49,8 @@ GLOBAL_PARAMS: Tuple[str, ...] def query_params( *es_query_params: str, body_params: Optional[List[str]] = ..., - body_name: Optional[str] = ... + body_name: Optional[str] = ..., + body_required: Optional[bool] = ... ) -> Callable[[Callable[..., T]], Callable[..., T]]: ... def _bulk_body( serializer: Serializer, body: Union[str, bytes, Mapping[str, Any], Iterable[Any]] diff --git a/test_elasticsearch/test_client/test_document.py b/test_elasticsearch/test_client/test_document.py new file mode 100644 index 000000000..fc1b67186 --- /dev/null +++ b/test_elasticsearch/test_client/test_document.py @@ -0,0 +1,33 @@ +# Licensed to Elasticsearch B.V. under one or more contributor +# license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright +# ownership. Elasticsearch B.V. licenses this file to you under +# the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +from test_elasticsearch.test_cases import ElasticsearchTestCase + + +class TestIndices(ElasticsearchTestCase): + def test_create_document(self): + self.client.create(index="test-index", id="test-id", document={"key": "value"}) + self.assert_url_called("PUT", "/test-index/_create/test-id") + + def test_create_document_with_type(self): + self.client.create( + index="test-index", + id="test-id", + doc_type="test-type", + document={"key": "value"}, + ) + self.assert_url_called("PUT", "/test-index/test-type/test-id/_create") diff --git a/test_elasticsearch/test_client/test_indices.py b/test_elasticsearch/test_client/test_indices.py index 45c5f8b70..8dc17dcc8 100644 --- a/test_elasticsearch/test_client/test_indices.py +++ b/test_elasticsearch/test_client/test_indices.py @@ -20,15 +20,15 @@ class TestIndices(ElasticsearchTestCase): def test_create_one_index(self): - self.client.indices.create("test-index") + self.client.indices.create(index="test-index") self.assert_url_called("PUT", "/test-index") def test_delete_multiple_indices(self): - self.client.indices.delete(["test-index", "second.index", "third/index"]) + self.client.indices.delete(index=["test-index", "second.index", "third/index"]) self.assert_url_called("DELETE", "/test-index,second.index,third%2Findex") def test_exists_index(self): - self.client.indices.exists("second.index,third/index") + self.client.indices.exists(index="second.index,third/index") self.assert_url_called("HEAD", "/second.index,third%2Findex") def test_passing_empty_value_for_required_param_raises_exception(self): diff --git a/test_elasticsearch/test_client/test_utils.py b/test_elasticsearch/test_client/test_utils.py index 3d9b90dae..59b236d53 100644 --- a/test_elasticsearch/test_client/test_utils.py +++ b/test_elasticsearch/test_client/test_utils.py @@ -44,6 +44,15 @@ def func_to_wrap(self, *args, **kwargs): def func_with_body_params(self, *args, **kwargs): self.calls.append((args, kwargs)) + @query_params( + "query_only", + "query_and_body", + body_params=["query_and_body", "body_only"], + body_required=True, + ) + def func_with_body_params_required(self, *args, **kwargs): + self.calls.append((args, kwargs)) + @query_params("query_only", body_name="named_body") def func_with_named_body(self, *args, **kwargs): self.calls.append((args, kwargs)) @@ -309,6 +318,37 @@ def test_named_body_params(self): "See https://github.com/elastic/elasticsearch-py/issues/1698 for more information" ) + def test_body_required_with_body_fields(self): + self.func_with_body_params_required(query_only=True) + assert self.calls[-1] == ( + (), + {"body": {}, "headers": {}, "params": {"query_only": b"true"}}, + ) + + self.func_with_body_params_required(body_only=True) + assert self.calls[-1] == ( + (), + {"body": {"body_only": True}, "headers": {}, "params": {}}, + ) + + self.func_with_body_params_required(query_and_body=True) + assert self.calls[-1] == ( + (), + {"body": {"query_and_body": True}, "headers": {}, "params": {}}, + ) + + self.func_with_body_params_required(body={}) + assert self.calls[-1] == ((), {"body": {}, "headers": {}, "params": {}}) + + self.func_with_body_params_required(body={"hello": "world"}) + assert self.calls[-1] == ( + (), + {"body": {"hello": "world"}, "headers": {}, "params": {}}, + ) + + self.func_with_body_params_required() + assert self.calls[-1] == ((), {"body": {}, "headers": {}, "params": {}}) + class TestMakePath(TestCase): def test_handles_unicode(self): diff --git a/test_elasticsearch/test_server/test_rest_api_spec.py b/test_elasticsearch/test_server/test_rest_api_spec.py index 34643dbd2..181d17c67 100644 --- a/test_elasticsearch/test_server/test_rest_api_spec.py +++ b/test_elasticsearch/test_server/test_rest_api_spec.py @@ -115,6 +115,7 @@ APIS_WITH_BODY_FIELDS = { "search", "update", + "indices.create", }