Skip to content

Commit

Permalink
Updated CHANGELOG.md and applied working sample on snapshot.md
Browse files Browse the repository at this point in the history
Signed-off-by: Raman Saparkhan <[email protected]>
  • Loading branch information
roma2023 committed Sep 5, 2023
1 parent 95fc63f commit dd29ac4
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 8 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
43 changes: 35 additions & 8 deletions guides/snapshot.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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')
```

0 comments on commit dd29ac4

Please sign in to comment.