Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix point in time rest api #191

Merged
merged 12 commits into from
Nov 2, 2022
27 changes: 19 additions & 8 deletions opensearchpy/_async/client/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -1948,26 +1948,37 @@ async def get_script_languages(self, params=None, headers=None):
)

@query_params()
async def close_point_in_time(self, body=None, params=None, headers=None):
async def list_all_point_in_time(self, params=None, headers=None):
"""
Close a point in time
Returns the list of point in times which are alive
Arpit-Bandejiya marked this conversation as resolved.
Show resolved Hide resolved
"""
return await self.transport.perform_request(
"GET", _make_path("_search", "point_in_time", "all"), params=params, headers=headers
)

@query_params()
async def delete_point_in_time(self, all=None, body=None, params=None, headers=None):
"""
Delete a point in time


:arg body: a point-in-time id to close
:arg body: a point-in-time id to delete
:arg all: set it to `_all` to delete all alive point in time.
"""
return await self.transport.perform_request(
"DELETE", "/_pit", params=params, headers=headers, body=body
"DELETE", _make_path("_search", "point_in_time", all), params=params, headers=headers, body=body
)


@query_params(
"expand_wildcards", "ignore_unavailable", "keep_alive", "preference", "routing"
)
async def open_point_in_time(self, index=None, params=None, headers=None):
async def create_point_in_time(self, index=None, params=None, headers=None):
"""
Open a point in time that can be used in subsequent searches
Create a point in time that can be used in subsequent searches


:arg index: A comma-separated list of index names to open point
:arg index: A comma-separated list of index names to create point
in time; use `_all` or empty string to perform the operation on all
indices
:arg expand_wildcards: Whether to expand wildcard expression to
Expand All @@ -1981,7 +1992,7 @@ async def open_point_in_time(self, index=None, params=None, headers=None):
:arg routing: Specific routing value
"""
return await self.transport.perform_request(
"POST", _make_path(index, "_pit"), params=params, headers=headers
"POST", _make_path(index, "_search", "point_in_time"), params=params, headers=headers
)

@query_params()
Expand Down
25 changes: 18 additions & 7 deletions opensearchpy/client/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -1947,23 +1947,34 @@ def get_script_languages(self, params=None, headers=None):
)

@query_params()
def close_point_in_time(self, body=None, params=None, headers=None):
def list_all_point_in_time(self, params=None, headers=None):
"""
Close a point in time
Returns the list of active point in times searches
"""
return self.transport.perform_request(
"GET", _make_path("_search", "point_in_time", "all"), params=params, headers=headers
)


@query_params()
def delete_point_in_time(self, all=None, body=None, params=None, headers=None):
"""
Delete a point in time


:arg body: a point-in-time id to close
:arg body: a point-in-time id to delete
:arg all: set it to `_all` to delete all alive point in time.
"""
return self.transport.perform_request(
"DELETE", "/_pit", params=params, headers=headers, body=body
"DELETE", _make_path("_search", "point_in_time", all), params=params, headers=headers, body=body
)

@query_params(
"expand_wildcards", "ignore_unavailable", "keep_alive", "preference", "routing"
)
def open_point_in_time(self, index=None, params=None, headers=None):
def create_point_in_time(self, index=None, params=None, headers=None):
"""
Open a point in time that can be used in subsequent searches
Create a point in time that can be used in subsequent searches


:arg index: A comma-separated list of index names to open point
Expand All @@ -1980,7 +1991,7 @@ def open_point_in_time(self, index=None, params=None, headers=None):
:arg routing: Specific routing value
"""
return self.transport.perform_request(
"POST", _make_path(index, "_pit"), params=params, headers=headers
"POST", _make_path(index,"_search","point_in_time"), params=params, headers=headers
)

@query_params()
Expand Down
46 changes: 46 additions & 0 deletions test_opensearchpy/test_client/test_point_in_time.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
# 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.
#
Arpit-Bandejiya marked this conversation as resolved.
Show resolved Hide resolved
# 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_opensearchpy.test_cases import OpenSearchTestCase


class TestPointInTime(OpenSearchTestCase):
def test_create_one_point_in_time(self):
index_name = "test-index"
self.client.create_point_in_time(index=index_name)
self.assert_url_called("POST", "/test-index/_search/point_in_time")

def test_delete_one_point_in_time(self):
self.client.delete_point_in_time(body={})

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we should not call delete with empty body . its delete all or delete with list of pit ids in empty.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, have updated it in the new revision. Thanks!

self.assert_url_called("DELETE", "/_search/point_in_time")

def test_delete_all_point_in_time(self):
self.client.delete_point_in_time(body={}, all="_all")
self.assert_url_called("DELETE", "/_search/point_in_time/_all")

def test_list_all_point_in_time(self):
self.client.list_all_point_in_time()
self.assert_url_called("GET", "/_search/point_in_time/all")