From dd29ac4c4ad15331206d10dd9cb4b31971e2bed2 Mon Sep 17 00:00:00 2001 From: Raman Saparkhan Date: Wed, 6 Sep 2023 00:17:30 +0300 Subject: [PATCH] Updated CHANGELOG.md and applied working sample on snapshot.md Signed-off-by: Raman Saparkhan --- CHANGELOG.md | 1 + guides/snapshot.md | 43 +++++++++++++++++++++++++++++++++++-------- 2 files changed, 36 insertions(+), 8 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 040fb8ab..0c26f7bb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -42,6 +42,7 @@ Inspired from [Keep a Changelog](https://keepachangelog.com/en/1.0.0/) - Improved CI performance of integration with unreleased OpenSearch ([#318](https://github.com/opensearch-project/opensearch-py/pull/318)) - Added k-NN guide and samples ([#449](https://github.com/opensearch-project/opensearch-py/pull/449)) - Added the ability to run tests matching a pattern to `.ci/run-tests` ([#454](https://github.com/opensearch-project/opensearch-py/pull/454)) +- Added new guide: `snapshot.md` for Snapshot API. ([#486](https://github.com/opensearch-project/opensearch-py/pull/429)) ### Changed - Moved security from `plugins` to `clients` ([#442](https://github.com/opensearch-project/opensearch-py/pull/442)) - Updated Security Client APIs ([#450](https://github.com/opensearch-project/opensearch-py/pull/450)) diff --git a/guides/snapshot.md b/guides/snapshot.md index cd5fc129..2b669d39 100644 --- a/guides/snapshot.md +++ b/guides/snapshot.md @@ -3,18 +3,45 @@ In this guide, we will look at some snapshot actions that allow you to manage an ## Setup -Let's create a client instance, and an index named `movies`: +Let's create a client instance, and an index named `test-index`: ```python from opensearchpy import OpenSearch +# connect to OpenSearch + +host = 'localhost' +port = 9200 +auth = ('admin', 'admin') # For testing only. Don't store credentials in code. + client = OpenSearch( - hosts=['https://admin:admin@localhost:9200'], - use_ssl=True, - verify_certs=False + hosts = [{'host': host, 'port': port}], + http_auth = auth, + use_ssl = True, + verify_certs = False, + ssl_show_warn = False +) + +info = client.info() +print(f"Welcome to {info['version']['distribution']} {info['version']['number']}!") + +# create an index + +index_name = 'test-index' + +index_body = { + 'settings': { + 'index': { + 'number_of_shards': 4 + } + } +} + +response = client.indices.create( + index_name, + body=index_body ) print(client.info()) # Check server info and make sure the client is connected -client.indices.create(index='movies') ``` ## API Actions ### Create Snapshot Repository @@ -34,7 +61,7 @@ client.snapshot.create_repository(repository='my_repository', body=repo_body) To create a snapshot of an index, you can use the `create` method from the `snapshot` API. The following example creates a snapshot named `my_snapshot` for the movies index: ```python -client.snapshot.create(repository='my_repository', snapshot='my_snapshot', body={"indices": "movies"}) +client.snapshot.create(repository='my_repository', snapshot='my_snapshot', body={"indices": "test-index"}) ``` ### Verify Snapshot Repository @@ -100,9 +127,9 @@ response = client.snapshot.repository_analyze(repository='my_repository') ## Cleanup -Finally, let's delete the `movies` index and clean up all the snapshots and the repository: +Finally, let's delete the `test-index` index and clean up all the snapshots and the repository: ```python -client.indices.delete(index='movies') +client.indices.delete(index='test-index') client.snapshot.delete(repository='my_repository', snapshot='my_snapshot') client.snapshot.delete_repository(repository='my_repository') ``` \ No newline at end of file