Skip to content

Commit

Permalink
Updated opensearch-py to reflect the latest OpenSearch API spec (2024…
Browse files Browse the repository at this point in the history
…-09-05)

Signed-off-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
  • Loading branch information
saimedhi authored and github-actions[bot] committed Sep 5, 2024
1 parent a24b9f3 commit 3d6dae9
Show file tree
Hide file tree
Showing 9 changed files with 425 additions and 5 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
4 changes: 4 additions & 0 deletions opensearchpy/_async/client/cluster.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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")
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -1026,4 +1029,5 @@ async def put_weighted_routing(
_make_path("_cluster", "routing", "awareness", attribute, "weights"),
params=params,
headers=headers,
body=body,
)
4 changes: 4 additions & 0 deletions opensearchpy/_async/client/plugins.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -26,6 +27,7 @@


class PluginsClient(NamespacedClient):
asynchronous_search: Any
alerting: Any
index_management: Any
knn: Any
Expand All @@ -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)
Expand All @@ -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",
Expand Down
163 changes: 163 additions & 0 deletions opensearchpy/_async/plugins/asynchronous_search.py
Original file line number Diff line number Diff line change
@@ -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,
)
32 changes: 32 additions & 0 deletions opensearchpy/_async/plugins/ml.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
)
4 changes: 4 additions & 0 deletions opensearchpy/client/cluster.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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")
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -1026,4 +1029,5 @@ def put_weighted_routing(
_make_path("_cluster", "routing", "awareness", attribute, "weights"),
params=params,
headers=headers,
body=body,
)
27 changes: 22 additions & 5 deletions opensearchpy/client/plugins.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
Expand All @@ -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):
Expand Down
Loading

0 comments on commit 3d6dae9

Please sign in to comment.