From 3d6dae9a60e51a36981c3ba7f63e13a83c8e8182 Mon Sep 17 00:00:00 2001 From: saimedhi <117196660+saimedhi@users.noreply.github.com> Date: Thu, 5 Sep 2024 03:35:36 +0000 Subject: [PATCH] Updated opensearch-py to reflect the latest OpenSearch API spec (2024-09-05) Signed-off-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> --- CHANGELOG.md | 1 + opensearchpy/_async/client/cluster.py | 4 + opensearchpy/_async/client/plugins.py | 4 + .../_async/plugins/asynchronous_search.py | 163 ++++++++++++++++++ opensearchpy/_async/plugins/ml.py | 32 ++++ opensearchpy/client/cluster.py | 4 + opensearchpy/client/plugins.py | 27 ++- opensearchpy/plugins/asynchronous_search.py | 163 ++++++++++++++++++ opensearchpy/plugins/ml.py | 32 ++++ 9 files changed, 425 insertions(+), 5 deletions(-) create mode 100644 opensearchpy/_async/plugins/asynchronous_search.py create mode 100644 opensearchpy/plugins/asynchronous_search.py diff --git a/CHANGELOG.md b/CHANGELOG.md index 672fd065..b234ec81 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -31,6 +31,7 @@ Inspired from [Keep a Changelog](https://keepachangelog.com/en/1.0.0/) - Fixed the use of `minimum_should_match` with `Bool` to allow the use of string-based value (percent string, combination). ([#780](https://github.com/opensearch-project/opensearch-py/pull/780)) - Fixed incorrect `retry_on_conflict` type ([#795](https://github.com/opensearch-project/opensearch-py/pull/795)) ### Updated APIs +- Updated opensearch-py APIs to reflect [opensearch-api-specification@0733e62](https://github.com/opensearch-project/opensearch-api-specification/commit/0733e620ba6c8093fa9c6af46c1bfd0479e24e42) - Updated opensearch-py APIs to reflect [opensearch-api-specification@9d3bc34](https://github.com/opensearch-project/opensearch-api-specification/commit/9d3bc340ccd7d049e7d6e14a4aff2293780cb446) ### Dependencies - Bump `pytest-asyncio` from <=0.23.7 to <=0.23.8 ([#787](https://github.com/opensearch-project/opensearch-py/pull/787)) diff --git a/opensearchpy/_async/client/cluster.py b/opensearchpy/_async/client/cluster.py index 655025c4..a8778dfb 100644 --- a/opensearchpy/_async/client/cluster.py +++ b/opensearchpy/_async/client/cluster.py @@ -854,6 +854,7 @@ async def delete_decommission_awareness( @query_params("error_trace", "filter_path", "human", "pretty", "source") async def delete_weighted_routing( self, + body: Any = None, params: Any = None, headers: Any = None, ) -> Any: @@ -877,6 +878,7 @@ async def delete_weighted_routing( "/_cluster/routing/awareness/weights", params=params, headers=headers, + body=body, ) @query_params("error_trace", "filter_path", "human", "pretty", "source") @@ -999,6 +1001,7 @@ async def put_decommission_awareness( async def put_weighted_routing( self, attribute: Any, + body: Any = None, params: Any = None, headers: Any = None, ) -> Any: @@ -1026,4 +1029,5 @@ async def put_weighted_routing( _make_path("_cluster", "routing", "awareness", attribute, "weights"), params=params, headers=headers, + body=body, ) diff --git a/opensearchpy/_async/client/plugins.py b/opensearchpy/_async/client/plugins.py index acf1ec57..ef81da3a 100644 --- a/opensearchpy/_async/client/plugins.py +++ b/opensearchpy/_async/client/plugins.py @@ -11,6 +11,7 @@ from typing import Any from ..plugins.alerting import AlertingClient +from ..plugins.asynchronous_search import AsynchronousSearchClient from ..plugins.index_management import IndexManagementClient from ..plugins.knn import KnnClient from ..plugins.ml import MlClient @@ -26,6 +27,7 @@ class PluginsClient(NamespacedClient): + asynchronous_search: Any alerting: Any index_management: Any knn: Any @@ -41,6 +43,7 @@ class PluginsClient(NamespacedClient): def __init__(self, client: Client) -> None: super().__init__(client) + self.asynchronous_search = AsynchronousSearchClient(client) self.alerting = AlertingClient(client) self.index_management = IndexManagementClient(client) self.knn = KnnClient(client) @@ -59,6 +62,7 @@ def _dynamic_lookup(self, client: Any) -> None: # Issue : https://github.com/opensearch-project/opensearch-py/issues/90#issuecomment-1003396742 plugins = [ + "asynchronous_search", "alerting", "index_management", "knn", diff --git a/opensearchpy/_async/plugins/asynchronous_search.py b/opensearchpy/_async/plugins/asynchronous_search.py new file mode 100644 index 00000000..d14b2351 --- /dev/null +++ b/opensearchpy/_async/plugins/asynchronous_search.py @@ -0,0 +1,163 @@ +# SPDX-License-Identifier: Apache-2.0 +# +# The OpenSearch Contributors require contributions made to +# this file be licensed under the Apache-2.0 license or a +# compatible open source license. +# +# Modifications Copyright OpenSearch Contributors. See +# GitHub history for details. + +# ------------------------------------------------------------------------------------------ +# THIS CODE IS AUTOMATICALLY GENERATED AND MANUAL EDITS WILL BE LOST +# +# To contribute, kindly make modifications in the opensearch-py client generator +# or in the OpenSearch API specification, and run `nox -rs generate`. See DEVELOPER_GUIDE.md +# and https://github.com/opensearch-project/opensearch-api-specification for details. +# -----------------------------------------------------------------------------------------+ + + +from typing import Any + +from ..client.utils import SKIP_IN_PATH, NamespacedClient, _make_path, query_params + + +class AsynchronousSearchClient(NamespacedClient): + @query_params("error_trace", "filter_path", "human", "pretty", "source") + async def delete( + self, + id: Any, + params: Any = None, + headers: Any = None, + ) -> Any: + """ + Delete asynchronous search. + + + :arg error_trace: Whether to include the stack trace of returned + errors. + :arg filter_path: Comma-separated list of filters used to reduce + the response. + :arg human: Whether to return human readable values for + statistics. + :arg pretty: Whether to pretty format the returned JSON + response. + :arg source: The URL-encoded request definition. Useful for + libraries that do not accept a request body for non-POST requests. + """ + if id in SKIP_IN_PATH: + raise ValueError("Empty value passed for a required argument 'id'.") + + return await self.transport.perform_request( + "DELETE", + _make_path("_plugins", "_asynchronous_search", id), + params=params, + headers=headers, + ) + + @query_params("error_trace", "filter_path", "human", "pretty", "source") + async def get( + self, + id: Any, + params: Any = None, + headers: Any = None, + ) -> Any: + """ + Get partial responses from asynchronous search. + + + :arg error_trace: Whether to include the stack trace of returned + errors. + :arg filter_path: Comma-separated list of filters used to reduce + the response. + :arg human: Whether to return human readable values for + statistics. + :arg pretty: Whether to pretty format the returned JSON + response. + :arg source: The URL-encoded request definition. Useful for + libraries that do not accept a request body for non-POST requests. + """ + if id in SKIP_IN_PATH: + raise ValueError("Empty value passed for a required argument 'id'.") + + return await self.transport.perform_request( + "GET", + _make_path("_plugins", "_asynchronous_search", id), + params=params, + headers=headers, + ) + + @query_params( + "error_trace", + "filter_path", + "human", + "index", + "keep_alive", + "keep_on_completion", + "pretty", + "source", + "wait_for_completion_timeout", + ) + async def search( + self, + body: Any = None, + params: Any = None, + headers: Any = None, + ) -> Any: + """ + Perform an asynchronous search. + + + :arg error_trace: Whether to include the stack trace of returned + errors. + :arg filter_path: Comma-separated list of filters used to reduce + the response. + :arg human: Whether to return human readable values for + statistics. + :arg index: The name of the index to be searched. + :arg keep_alive: The amount of time that the result is saved in + the cluster. + :arg keep_on_completion: Whether you want to save the results in + the cluster after the search is complete. + :arg pretty: Whether to pretty format the returned JSON + response. + :arg source: The URL-encoded request definition. Useful for + libraries that do not accept a request body for non-POST requests. + :arg wait_for_completion_timeout: The amount of time that you + plan to wait for the results. + """ + return await self.transport.perform_request( + "POST", + "/_plugins/_asynchronous_search", + params=params, + headers=headers, + body=body, + ) + + @query_params("error_trace", "filter_path", "human", "pretty", "source") + async def stats( + self, + params: Any = None, + headers: Any = None, + ) -> Any: + """ + Monitoring of asynchronous searches that are running, completed, and/or + persisted. + + + :arg error_trace: Whether to include the stack trace of returned + errors. + :arg filter_path: Comma-separated list of filters used to reduce + the response. + :arg human: Whether to return human readable values for + statistics. + :arg pretty: Whether to pretty format the returned JSON + response. + :arg source: The URL-encoded request definition. Useful for + libraries that do not accept a request body for non-POST requests. + """ + return await self.transport.perform_request( + "GET", + "/_plugins/_asynchronous_search/stats", + params=params, + headers=headers, + ) diff --git a/opensearchpy/_async/plugins/ml.py b/opensearchpy/_async/plugins/ml.py index b48bf775..6bcee98c 100644 --- a/opensearchpy/_async/plugins/ml.py +++ b/opensearchpy/_async/plugins/ml.py @@ -307,3 +307,35 @@ async def undeploy_model( params=params, headers=headers, ) + + @query_params("error_trace", "filter_path", "human", "pretty", "source") + async def delete_task( + self, + task_id: Any, + params: Any = None, + headers: Any = None, + ) -> Any: + """ + Deletes a task. + + + :arg error_trace: Whether to include the stack trace of returned + errors. + :arg filter_path: Comma-separated list of filters used to reduce + the response. + :arg human: Whether to return human readable values for + statistics. + :arg pretty: Whether to pretty format the returned JSON + response. + :arg source: The URL-encoded request definition. Useful for + libraries that do not accept a request body for non-POST requests. + """ + if task_id in SKIP_IN_PATH: + raise ValueError("Empty value passed for a required argument 'task_id'.") + + return await self.transport.perform_request( + "DELETE", + _make_path("_plugins", "_ml", "tasks", task_id), + params=params, + headers=headers, + ) diff --git a/opensearchpy/client/cluster.py b/opensearchpy/client/cluster.py index 271ed4d3..e2e1cab9 100644 --- a/opensearchpy/client/cluster.py +++ b/opensearchpy/client/cluster.py @@ -854,6 +854,7 @@ def delete_decommission_awareness( @query_params("error_trace", "filter_path", "human", "pretty", "source") def delete_weighted_routing( self, + body: Any = None, params: Any = None, headers: Any = None, ) -> Any: @@ -877,6 +878,7 @@ def delete_weighted_routing( "/_cluster/routing/awareness/weights", params=params, headers=headers, + body=body, ) @query_params("error_trace", "filter_path", "human", "pretty", "source") @@ -999,6 +1001,7 @@ def put_decommission_awareness( def put_weighted_routing( self, attribute: Any, + body: Any = None, params: Any = None, headers: Any = None, ) -> Any: @@ -1026,4 +1029,5 @@ def put_weighted_routing( _make_path("_cluster", "routing", "awareness", attribute, "weights"), params=params, headers=headers, + body=body, ) diff --git a/opensearchpy/client/plugins.py b/opensearchpy/client/plugins.py index 526e1cab..ef81da3a 100644 --- a/opensearchpy/client/plugins.py +++ b/opensearchpy/client/plugins.py @@ -11,6 +11,7 @@ from typing import Any from ..plugins.alerting import AlertingClient +from ..plugins.asynchronous_search import AsynchronousSearchClient from ..plugins.index_management import IndexManagementClient from ..plugins.knn import KnnClient from ..plugins.ml import MlClient @@ -26,12 +27,23 @@ class PluginsClient(NamespacedClient): + asynchronous_search: Any alerting: Any index_management: Any + knn: Any + ml: Any + notifications: Any + observability: Any + ppl: Any + query: Any + rollups: Any + sql: Any + transforms: Any def __init__(self, client: Client) -> None: super().__init__(client) + self.asynchronous_search = AsynchronousSearchClient(client) self.alerting = AlertingClient(client) self.index_management = IndexManagementClient(client) self.knn = KnnClient(client) @@ -50,13 +62,18 @@ def _dynamic_lookup(self, client: Any) -> None: # Issue : https://github.com/opensearch-project/opensearch-py/issues/90#issuecomment-1003396742 plugins = [ - # "query_workbench", - # "reporting", - # "notebooks", + "asynchronous_search", "alerting", - # "anomaly_detection", - # "trace_analytics", "index_management", + "knn", + "ml", + "notifications", + "observability", + "ppl", + "query", + "rollups", + "sql", + "transforms", ] for plugin in plugins: if not hasattr(client, plugin): diff --git a/opensearchpy/plugins/asynchronous_search.py b/opensearchpy/plugins/asynchronous_search.py new file mode 100644 index 00000000..de90e7b3 --- /dev/null +++ b/opensearchpy/plugins/asynchronous_search.py @@ -0,0 +1,163 @@ +# SPDX-License-Identifier: Apache-2.0 +# +# The OpenSearch Contributors require contributions made to +# this file be licensed under the Apache-2.0 license or a +# compatible open source license. +# +# Modifications Copyright OpenSearch Contributors. See +# GitHub history for details. + +# ------------------------------------------------------------------------------------------ +# THIS CODE IS AUTOMATICALLY GENERATED AND MANUAL EDITS WILL BE LOST +# +# To contribute, kindly make modifications in the opensearch-py client generator +# or in the OpenSearch API specification, and run `nox -rs generate`. See DEVELOPER_GUIDE.md +# and https://github.com/opensearch-project/opensearch-api-specification for details. +# -----------------------------------------------------------------------------------------+ + + +from typing import Any + +from ..client.utils import SKIP_IN_PATH, NamespacedClient, _make_path, query_params + + +class AsynchronousSearchClient(NamespacedClient): + @query_params("error_trace", "filter_path", "human", "pretty", "source") + def delete( + self, + id: Any, + params: Any = None, + headers: Any = None, + ) -> Any: + """ + Delete asynchronous search. + + + :arg error_trace: Whether to include the stack trace of returned + errors. + :arg filter_path: Comma-separated list of filters used to reduce + the response. + :arg human: Whether to return human readable values for + statistics. + :arg pretty: Whether to pretty format the returned JSON + response. + :arg source: The URL-encoded request definition. Useful for + libraries that do not accept a request body for non-POST requests. + """ + if id in SKIP_IN_PATH: + raise ValueError("Empty value passed for a required argument 'id'.") + + return self.transport.perform_request( + "DELETE", + _make_path("_plugins", "_asynchronous_search", id), + params=params, + headers=headers, + ) + + @query_params("error_trace", "filter_path", "human", "pretty", "source") + def get( + self, + id: Any, + params: Any = None, + headers: Any = None, + ) -> Any: + """ + Get partial responses from asynchronous search. + + + :arg error_trace: Whether to include the stack trace of returned + errors. + :arg filter_path: Comma-separated list of filters used to reduce + the response. + :arg human: Whether to return human readable values for + statistics. + :arg pretty: Whether to pretty format the returned JSON + response. + :arg source: The URL-encoded request definition. Useful for + libraries that do not accept a request body for non-POST requests. + """ + if id in SKIP_IN_PATH: + raise ValueError("Empty value passed for a required argument 'id'.") + + return self.transport.perform_request( + "GET", + _make_path("_plugins", "_asynchronous_search", id), + params=params, + headers=headers, + ) + + @query_params( + "error_trace", + "filter_path", + "human", + "index", + "keep_alive", + "keep_on_completion", + "pretty", + "source", + "wait_for_completion_timeout", + ) + def search( + self, + body: Any = None, + params: Any = None, + headers: Any = None, + ) -> Any: + """ + Perform an asynchronous search. + + + :arg error_trace: Whether to include the stack trace of returned + errors. + :arg filter_path: Comma-separated list of filters used to reduce + the response. + :arg human: Whether to return human readable values for + statistics. + :arg index: The name of the index to be searched. + :arg keep_alive: The amount of time that the result is saved in + the cluster. + :arg keep_on_completion: Whether you want to save the results in + the cluster after the search is complete. + :arg pretty: Whether to pretty format the returned JSON + response. + :arg source: The URL-encoded request definition. Useful for + libraries that do not accept a request body for non-POST requests. + :arg wait_for_completion_timeout: The amount of time that you + plan to wait for the results. + """ + return self.transport.perform_request( + "POST", + "/_plugins/_asynchronous_search", + params=params, + headers=headers, + body=body, + ) + + @query_params("error_trace", "filter_path", "human", "pretty", "source") + def stats( + self, + params: Any = None, + headers: Any = None, + ) -> Any: + """ + Monitoring of asynchronous searches that are running, completed, and/or + persisted. + + + :arg error_trace: Whether to include the stack trace of returned + errors. + :arg filter_path: Comma-separated list of filters used to reduce + the response. + :arg human: Whether to return human readable values for + statistics. + :arg pretty: Whether to pretty format the returned JSON + response. + :arg source: The URL-encoded request definition. Useful for + libraries that do not accept a request body for non-POST requests. + """ + return self.transport.perform_request( + "GET", + "/_plugins/_asynchronous_search/stats", + params=params, + headers=headers, + ) diff --git a/opensearchpy/plugins/ml.py b/opensearchpy/plugins/ml.py index 1183bf5e..0f6daa8f 100644 --- a/opensearchpy/plugins/ml.py +++ b/opensearchpy/plugins/ml.py @@ -307,3 +307,35 @@ def undeploy_model( params=params, headers=headers, ) + + @query_params("error_trace", "filter_path", "human", "pretty", "source") + def delete_task( + self, + task_id: Any, + params: Any = None, + headers: Any = None, + ) -> Any: + """ + Deletes a task. + + + :arg error_trace: Whether to include the stack trace of returned + errors. + :arg filter_path: Comma-separated list of filters used to reduce + the response. + :arg human: Whether to return human readable values for + statistics. + :arg pretty: Whether to pretty format the returned JSON + response. + :arg source: The URL-encoded request definition. Useful for + libraries that do not accept a request body for non-POST requests. + """ + if task_id in SKIP_IN_PATH: + raise ValueError("Empty value passed for a required argument 'task_id'.") + + return self.transport.perform_request( + "DELETE", + _make_path("_plugins", "_ml", "tasks", task_id), + params=params, + headers=headers, + )