Fix point in time rest api (#191)
* Add change for point in time Signed-off-by: Arpit Bandejiya <[email protected]> * resolve minor comments Signed-off-by: Arpit Bandejiya <[email protected]> * Add Unit tests Signed-off-by: Arpit Bandejiya <[email protected]> * minor changes Signed-off-by: Arpit Bandejiya <[email protected]> * minor edits in API calls Signed-off-by: Arpit Bandejiya <[email protected]> * Fixing lint errors Signed-off-by: Arpit Bandejiya <[email protected]> * Add documentation for the new API Signed-off-by: Arpit Bandejiya <[email protected]> * minor nit fix Signed-off-by: Arpit Bandejiya <[email protected]> * minor nit fix Signed-off-by: Arpit Bandejiya <[email protected]> * Added license in test file Signed-off-by: Arpit Bandejiya <[email protected]> * Add ChangeLog Signed-off-by: Arpit Bandejiya <[email protected]> Signed-off-by: Arpit Bandejiya <[email protected]>
This commit is contained in:
+1
-1
@@ -3,8 +3,8 @@ Inspired from [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
|
||||
|
||||
## [Unreleased]
|
||||
### Added
|
||||
- Added Point in time API rest API([#191](https://github.com/opensearch-project/opensearch-py/pull/191))
|
||||
- Github workflow for changelog verification ([#218](https://github.com/opensearch-project/opensearch-py/pull/218))
|
||||
|
||||
### Changed
|
||||
|
||||
### Deprecated
|
||||
|
||||
@@ -10,7 +10,7 @@
|
||||
OpenSearch Python Client
|
||||
|
||||
- [Welcome!](https://github.com/opensearch-project/opensearch-py#welcome)
|
||||
- [Getting Started](https://github.com/opensearch-project/opensearch-py#getting-started)
|
||||
- [User guide](https://github.com/opensearch-project/opensearch-py#user-guide)
|
||||
- [API Doc](https://opensearch-project.github.io/opensearch-py/)
|
||||
- [Compatibility with OpenSearch](https://github.com/opensearch-project/opensearch-py#compatibility-with-opensearch)
|
||||
- [Project Resources](https://github.com/opensearch-project/opensearch-py#project-resources)
|
||||
|
||||
@@ -9,6 +9,8 @@
|
||||
- [Searching for a document](#searching-for-a-document)
|
||||
- [Deleting a document](#deleting-a-document)
|
||||
- [Deleting an index](#deleting-an-index)
|
||||
- [Making API Calls](#making-api-calls)
|
||||
- [Point in Time API](#point-in-time-api-calls)
|
||||
- [Using plugins](#using-plugins)
|
||||
- [Alerting plugin](#alerting-plugin)
|
||||
- [**Searching for monitors**](#searching-for-monitors)
|
||||
@@ -20,7 +22,7 @@
|
||||
- [Using IAM credentials for authentication](#using-iam-credentials-for-authentication)
|
||||
- [Pre-requisites to use `AWSV4SignerAuth`](#pre-requisites-to-use-awsv4signerauth)
|
||||
|
||||
# Getting Started with the OpenSearch Python Client
|
||||
# User guide of OpenSearch Python Client
|
||||
|
||||
## Setup
|
||||
|
||||
@@ -39,7 +41,9 @@ from opensearchpy import OpenSearch
|
||||
If you prefer to add the client manually or just want to examine the source code, see [opensearch-py on GitHub](https://github.com/opensearch-project/opensearch-py).
|
||||
|
||||
|
||||
## Sample code
|
||||
## Example
|
||||
In the example given below, we create a client, an index with non-default settings, insert a
|
||||
document in the index, search for the document, delete the document and finally delete the index.
|
||||
|
||||
### Creating a client
|
||||
|
||||
@@ -68,7 +72,6 @@ client = OpenSearch(
|
||||
ssl_show_warn = False,
|
||||
ca_certs = ca_certs_path
|
||||
)
|
||||
|
||||
```
|
||||
|
||||
### Creating an index
|
||||
@@ -183,6 +186,37 @@ response = client.indices.delete(
|
||||
print('\nDeleting index:')
|
||||
print(response)
|
||||
```
|
||||
## Making API Calls
|
||||
|
||||
### Point in Time API
|
||||
|
||||
```python
|
||||
# create a point in time on a index
|
||||
index_name = "test-index"
|
||||
response = client.create_point_in_time(index=index_name,
|
||||
keep_alive="1m")
|
||||
|
||||
pit_id = response.get("pit_id")
|
||||
print('\n Point in time ID:')
|
||||
print(pit_id)
|
||||
|
||||
# To list all point in time which are alive in the cluster
|
||||
response = client.list_all_point_in_time()
|
||||
print('\n List of all Point in Time:')
|
||||
print(response)
|
||||
|
||||
# To delete point in time
|
||||
pit_body = {
|
||||
"pit_id": [pit_id]
|
||||
}
|
||||
|
||||
# To delete all point in time
|
||||
# client.delete_point_in_time(body=None, all=True)
|
||||
response = client.delete_point_in_time(body=pit_body)
|
||||
|
||||
print('\n The deleted point in time:')
|
||||
print(response)
|
||||
```
|
||||
|
||||
## Using plugins
|
||||
|
||||
+1
-1
@@ -49,7 +49,7 @@ def format(session):
|
||||
session.install("black", "isort")
|
||||
|
||||
session.run("isort", "--profile=black", *SOURCE_FILES)
|
||||
session.run("black", "--target-version=py27", *SOURCE_FILES)
|
||||
session.run("black", "--target-version=py33", *SOURCE_FILES)
|
||||
session.run("python", "utils/license-headers.py", "fix", *SOURCE_FILES)
|
||||
|
||||
lint(session)
|
||||
|
||||
@@ -1950,26 +1950,46 @@ class AsyncOpenSearch(object):
|
||||
)
|
||||
|
||||
@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
|
||||
|
||||
|
||||
:arg body: a point-in-time id to close
|
||||
Returns the list of point in times which are alive
|
||||
"""
|
||||
return await self.transport.perform_request(
|
||||
"DELETE", "/_pit", params=params, headers=headers, body=body
|
||||
"GET",
|
||||
_make_path("_search", "point_in_time", "_all"),
|
||||
params=params,
|
||||
headers=headers,
|
||||
)
|
||||
|
||||
@query_params()
|
||||
async def delete_point_in_time(
|
||||
self, body=None, all=False, params=None, headers=None
|
||||
):
|
||||
"""
|
||||
Delete a point in time
|
||||
|
||||
|
||||
:arg body: a point-in-time id to delete
|
||||
:arg all: set it to `True` to delete all alive point in time.
|
||||
"""
|
||||
path = (
|
||||
_make_path("_search", "point_in_time", "_all")
|
||||
if all
|
||||
else _make_path("_search", "point_in_time")
|
||||
)
|
||||
return await self.transport.perform_request(
|
||||
"DELETE", path, 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
|
||||
@@ -1983,7 +2003,10 @@ class AsyncOpenSearch(object):
|
||||
: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()
|
||||
|
||||
@@ -1951,23 +1951,42 @@ class OpenSearch(object):
|
||||
)
|
||||
|
||||
@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
|
||||
|
||||
|
||||
:arg body: a point-in-time id to close
|
||||
Returns the list of active point in times searches
|
||||
"""
|
||||
return self.transport.perform_request(
|
||||
"DELETE", "/_pit", params=params, headers=headers, body=body
|
||||
"GET",
|
||||
_make_path("_search", "point_in_time", "_all"),
|
||||
params=params,
|
||||
headers=headers,
|
||||
)
|
||||
|
||||
@query_params()
|
||||
def delete_point_in_time(self, body=None, all=False, params=None, headers=None):
|
||||
"""
|
||||
Delete a point in time
|
||||
|
||||
|
||||
:arg body: a point-in-time id to delete
|
||||
:arg all: set it to `True` to delete all alive point in time.
|
||||
"""
|
||||
|
||||
path = (
|
||||
_make_path("_search", "point_in_time", "_all")
|
||||
if all
|
||||
else _make_path("_search", "point_in_time")
|
||||
)
|
||||
return self.transport.perform_request(
|
||||
"DELETE", path, 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
|
||||
@@ -1984,7 +2003,10 @@ class OpenSearch(object):
|
||||
: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()
|
||||
|
||||
@@ -0,0 +1,29 @@
|
||||
# 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.
|
||||
|
||||
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={"pit_id": ["Sample-PIT-ID"]})
|
||||
self.assert_url_called("DELETE", "/_search/point_in_time")
|
||||
|
||||
def test_delete_all_point_in_time(self):
|
||||
self.client.delete_point_in_time(all=True)
|
||||
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")
|
||||
Reference in New Issue
Block a user