Skip to content

Commit

Permalink
Updated Search Pipeline APIs and added tests
Browse files Browse the repository at this point in the history
Signed-off-by: saimedhi <saimedhi@amazon.com>
  • Loading branch information
saimedhi committed Apr 19, 2024
1 parent b47edf9 commit 9bb9d54
Show file tree
Hide file tree
Showing 4 changed files with 163 additions and 39 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ Inspired from [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
### Fixed
- Updated code generator to use native OpenAPI specification ([#721](https://github.com/opensearch-project/opensearch-py/pull/721))
### Updated APIs
- Updated opensearch-py APIs to reflect [opensearch-api-specification@7abde8a](https://github.com/opensearch-project/opensearch-api-specification/commit/7abde8af9fc5d1d9ded0ae023a6f7e355b10137f)
- Updated opensearch-py APIs to reflect [opensearch-api-specification@29faff0](https://github.com/opensearch-project/opensearch-api-specification/commit/29faff0709b2557acfd4c3c7e053a2c313413633)
### Security
### Dependencies
Expand Down
100 changes: 81 additions & 19 deletions opensearchpy/_async/client/search_pipeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,18 +22,28 @@


class SearchPipelineClient(NamespacedClient):
@query_params("error_trace", "filter_path", "human", "pretty", "source")
async def create(
@query_params(
"cluster_manager_timeout",
"error_trace",
"filter_path",
"human",
"pretty",
"source",
)
async def get(
self,
pipeline: Any,
body: Any,
id: Any,
params: Any = None,
headers: Any = None,
) -> Any:
"""
Creates or replaces the specified search pipeline.
Retrieves information about a specified search pipeline.
:arg id: Comma-separated list of search pipeline ids. Wildcards
supported.
:arg cluster_manager_timeout: operation timeout for connection
to cluster-manager node.
:arg error_trace: Whether to include the stack trace of returned
errors.
:arg filter_path: Comma-separated list of filters used to reduce
Expand All @@ -45,29 +55,78 @@ async def create(
:arg source: The URL-encoded request definition. Useful for
libraries that do not accept a request body for non-POST requests.
"""
for param in (pipeline, body):
if param in SKIP_IN_PATH:
raise ValueError("Empty value passed for a required argument.")
if id in SKIP_IN_PATH:
raise ValueError("Empty value passed for a required argument 'id'.")

return await self.transport.perform_request(
"PUT",
_make_path("_search", "pipeline", pipeline),
"GET", _make_path("_search", "pipeline", id), params=params, headers=headers
)

@query_params(
"cluster_manager_timeout",
"error_trace",
"filter_path",
"human",
"pretty",
"source",
"timeout",
)
async def delete(
self,
id: Any,
params: Any = None,
headers: Any = None,
) -> Any:
"""
Deletes the specified search pipeline.
:arg cluster_manager_timeout: Operation timeout for connection
to cluster-manager node.
: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.
:arg timeout: Operation timeout.
"""
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("_search", "pipeline", id),
params=params,
headers=headers,
body=body,
)

@query_params("error_trace", "filter_path", "human", "pretty", "source")
async def get(
@query_params(
"cluster_manager_timeout",
"error_trace",
"filter_path",
"human",
"pretty",
"source",
"timeout",
)
async def put(
self,
pipeline: Any,
id: Any,
body: Any,
params: Any = None,
headers: Any = None,
) -> Any:
"""
Retrieves information about a specified search pipeline.
Creates or replaces the specified search pipeline.
:arg cluster_manager_timeout: operation timeout for connection
to cluster-manager node.
:arg error_trace: Whether to include the stack trace of returned
errors.
:arg filter_path: Comma-separated list of filters used to reduce
Expand All @@ -78,13 +137,16 @@ async def get(
response.
:arg source: The URL-encoded request definition. Useful for
libraries that do not accept a request body for non-POST requests.
:arg timeout: Operation timeout.
"""
if pipeline in SKIP_IN_PATH:
raise ValueError("Empty value passed for a required argument 'pipeline'.")
for param in (id, body):
if param in SKIP_IN_PATH:
raise ValueError("Empty value passed for a required argument.")

return await self.transport.perform_request(
"GET",
_make_path("_search", "pipeline", pipeline),
"PUT",
_make_path("_search", "pipeline", id),
params=params,
headers=headers,
body=body,
)
100 changes: 81 additions & 19 deletions opensearchpy/client/search_pipeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,18 +22,28 @@


class SearchPipelineClient(NamespacedClient):
@query_params("error_trace", "filter_path", "human", "pretty", "source")
def create(
@query_params(
"cluster_manager_timeout",
"error_trace",
"filter_path",
"human",
"pretty",
"source",
)
def get(
self,
pipeline: Any,
body: Any,
id: Any,
params: Any = None,
headers: Any = None,
) -> Any:
"""
Creates or replaces the specified search pipeline.
Retrieves information about a specified search pipeline.
:arg id: Comma-separated list of search pipeline ids. Wildcards
supported.
:arg cluster_manager_timeout: operation timeout for connection
to cluster-manager node.
:arg error_trace: Whether to include the stack trace of returned
errors.
:arg filter_path: Comma-separated list of filters used to reduce
Expand All @@ -45,29 +55,78 @@ def create(
:arg source: The URL-encoded request definition. Useful for
libraries that do not accept a request body for non-POST requests.
"""
for param in (pipeline, body):
if param in SKIP_IN_PATH:
raise ValueError("Empty value passed for a required argument.")
if id in SKIP_IN_PATH:
raise ValueError("Empty value passed for a required argument 'id'.")

return self.transport.perform_request(
"PUT",
_make_path("_search", "pipeline", pipeline),
"GET", _make_path("_search", "pipeline", id), params=params, headers=headers
)

@query_params(
"cluster_manager_timeout",
"error_trace",
"filter_path",
"human",
"pretty",
"source",
"timeout",
)
def delete(
self,
id: Any,
params: Any = None,
headers: Any = None,
) -> Any:
"""
Deletes the specified search pipeline.
:arg cluster_manager_timeout: Operation timeout for connection
to cluster-manager node.
: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.
:arg timeout: Operation timeout.
"""
if id in SKIP_IN_PATH:
raise ValueError("Empty value passed for a required argument 'id'.")

return self.transport.perform_request(
"DELETE",
_make_path("_search", "pipeline", id),
params=params,
headers=headers,
body=body,
)

@query_params("error_trace", "filter_path", "human", "pretty", "source")
def get(
@query_params(
"cluster_manager_timeout",
"error_trace",
"filter_path",
"human",
"pretty",
"source",
"timeout",
)
def put(
self,
pipeline: Any,
id: Any,
body: Any,
params: Any = None,
headers: Any = None,
) -> Any:
"""
Retrieves information about a specified search pipeline.
Creates or replaces the specified search pipeline.
:arg cluster_manager_timeout: operation timeout for connection
to cluster-manager node.
:arg error_trace: Whether to include the stack trace of returned
errors.
:arg filter_path: Comma-separated list of filters used to reduce
Expand All @@ -78,13 +137,16 @@ def get(
response.
:arg source: The URL-encoded request definition. Useful for
libraries that do not accept a request body for non-POST requests.
:arg timeout: Operation timeout.
"""
if pipeline in SKIP_IN_PATH:
raise ValueError("Empty value passed for a required argument 'pipeline'.")
for param in (id, body):
if param in SKIP_IN_PATH:
raise ValueError("Empty value passed for a required argument.")

return self.transport.perform_request(
"GET",
_make_path("_search", "pipeline", pipeline),
"PUT",
_make_path("_search", "pipeline", id),
params=params,
headers=headers,
body=body,
)
1 change: 0 additions & 1 deletion test_opensearchpy/test_server/test_rest_api_spec.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,6 @@
# broken YAML tests on some releases
SKIP_TESTS = {
# Warning about date_histogram.interval deprecation is raised randomly
"OpenSearch-main/rest-api-spec/src/main/resources/rest-api-spec/test/search_pipeline/10_basic",
"OpenSearch-main/rest-api-spec/src/main/resources/rest-api-spec/test/pit/10_basic",
"OpenSearch-main/rest-api-spec/src/main/resources/rest-api-spec/test/indices/clone/40_wait_for_completion[0]",
"OpenSearch-main/rest-api-spec/src/main/resources/rest-api-spec/test/indices/forcemerge/20_wait_for_completion[0]",
Expand Down

0 comments on commit 9bb9d54

Please sign in to comment.