-
Notifications
You must be signed in to change notification settings - Fork 183
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
[CCI] Create advanced index actions guide #363
Closed
Nicksqain
wants to merge
9
commits into
opensearch-project:main
from
Nicksqain:advanced-index-actions-py-guide
Closed
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
797630a
Create advanced index actions guide
Nicksqain c885074
Add changelog entry
Nicksqain 64eb6c5
Merge branch 'main' into advanced-index-actions-py-guide
Nicksqain a055400
Add changelog entry
Nicksqain 764686f
Add link from users guide
Nicksqain 170f076
Add a TOC and capitalize anchors
Nicksqain aa842bb
Capitalize Index Actions
Nicksqain 3264254
Capitalize Split index, Clone index, Force merge index
Nicksqain 2e0a08d
Capitalize Split index, Clone index, Force merge index
Nicksqain File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,117 @@ | ||
# Advanced Index Actions Guide | ||
- [Advanced Index Actions](#advanced-index-actions) | ||
- [Setup](#setup) | ||
- [Api Actions](#api-actions) | ||
- [Clear Index Cache](#clear-index-cache) | ||
- [Flush Index](#flush-index) | ||
- [Refresh Index](#refresh-index) | ||
- [Open/Close Index](#open-close-index) | ||
- [Force Merge Index](#force-merge-index) | ||
- [Clone Index](#clone-index) | ||
- [Split Index](#split-index) | ||
- [Cleanup](#cleanup) | ||
# Advanced Index Actions | ||
Nicksqain marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
In this guide, we will look at some advanced index actions that are not covered in the [Index Lifecycle](index_lifecycle.md) guide. | ||
|
||
## Setup | ||
|
||
Let's create a client instance, and an index named `movies`: | ||
|
||
```python | ||
from opensearchpy import OpenSearch | ||
client = OpenSearch( | ||
hosts=['https://admin:admin@localhost:9200'], | ||
use_ssl=True, | ||
verify_certs=False | ||
) | ||
client.indices.create(index='movies') | ||
``` | ||
|
||
## API Actions | ||
|
||
### Clear Index Cache | ||
|
||
You can clear the cache of an index or indices by using the `indices.clear_cache` API action. The following example clears the cache of the `movies` index: | ||
|
||
```python | ||
client.indices.clear_cache(index='movies') | ||
``` | ||
|
||
By default, the `indices.clear_cache` API action clears all types of cache. To clear specific types of cache pass the the `query`, `fielddata`, or `request` parameter to the API action: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. remove one "the" after cache pass. |
||
|
||
```python | ||
client.indices.clear_cache(index='movies', query=True) | ||
client.indices.clear_cache(index='movies', fielddata=True, request=True) | ||
``` | ||
|
||
### Flush Index | ||
|
||
Sometimes you might want to flush an index or indices to make sure that all data in the transaction log is persisted to the index. To flush an index or indices use the `indices.flush` API action. The following example flushes the `movies` index: | ||
|
||
```python | ||
client.indices.flush(index='movies') | ||
``` | ||
|
||
### Refresh Index | ||
|
||
You can refresh an index or indices to make sure that all changes are available for search. To refresh an index or indices use the `indices.refresh` API action: | ||
|
||
```python | ||
client.indices.refresh(index='movies') | ||
``` | ||
|
||
### Open/Close Index | ||
|
||
You can close an index to prevent read and write operations on the index. A closed index does not have to maintain certain data structures that an opened index require, reducing the memory and disk space required by the index. The following example closes and reopens the `movies` index: | ||
|
||
```python | ||
client.indices.close(index='movies') | ||
client.indices.open(index='movies') | ||
``` | ||
|
||
### Force Merge Index | ||
|
||
You can force merge an index or indices to reduce the number of segments in the index. This can be useful if you have a large number of small segments in the index. Merging segments reduces the memory footprint of the index. Do note that this action is resource intensive and it is only recommended for read-only indices. The following example force merges the `movies` index: | ||
|
||
```python | ||
client.indices.forcemerge(index='movies') | ||
``` | ||
|
||
### Clone Index | ||
|
||
You can clone an index to create a new index with the same mappings, data, and MOST of the settings. The source index must be in read-only state for cloning. The following example blocks write operations from `movies` index, clones the said index to create a new index named `movies_clone`, then re-enables write: | ||
|
||
```python | ||
client.indices.put_settings(index='movies', body={'index': {'blocks': {'write': True}}}) | ||
client.indices.clone(index='movies', target='movies_clone') | ||
client.indices.put_settings(index='movies', body={'index': {'blocks': {'write': False}}}) | ||
``` | ||
|
||
### Split Index | ||
|
||
You can split an index into another index with more primary shards. The source index must be in read-only state for splitting. The following example create the read-only `books` index with 30 routing shards and 5 shards (which is divisible by 30), splits index into `bigger_books` with 10 shards (which is also divisible by 30), then re-enables write: | ||
|
||
```python | ||
client.indices.create( | ||
index='books', | ||
body={ 'settings': { | ||
'index': { 'number_of_shards': 5, | ||
'number_of_routing_shards': 30, | ||
'blocks': { 'write': True } } } }) | ||
|
||
client.indices.split( | ||
index='books', | ||
target='bigger_books', | ||
body={ 'settings': { 'index': { 'number_of_shards': 10 } } }) | ||
|
||
client.indices.put_settings(index='books', body={ 'index': { 'blocks': { 'write': False } } }) | ||
``` | ||
|
||
## Cleanup | ||
|
||
Let's delete all the indices we created in this guide: | ||
|
||
```python | ||
client.indices.delete(index=['movies', 'books', 'movies_clone', 'bigger_books']) | ||
``` |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This link is not working.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@dblock This guide has broken linking because of the use of
[Open/Close Index](#open-close-index)
syntax. I think the/
character is breaking the#open-close-index
link, but not sure. Regardless, I need to change the section title to use aOpen or close index
& make the hash link#open-or-close-index
.(or something similar)Is the section title I suggested okay to you? Or would you prefer some other title/hash-link?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perfectly fine!