From dedc1cbbd23c08a2621c96bd01c5b2c5855f674d Mon Sep 17 00:00:00 2001 From: Alexei Karikov <karikov.alist.ru@gmail.com> Date: Sat, 8 Apr 2023 15:23:59 +0600 Subject: [PATCH 1/2] Create advanced index actions guide Signed-off-by: Alexei Karikov <karikov.alist.ru@gmail.com> --- guides/advanced_index_actions.md | 91 ++++++++++++++++++++++++++++++++ 1 file changed, 91 insertions(+) create mode 100644 guides/advanced_index_actions.md diff --git a/guides/advanced_index_actions.md b/guides/advanced_index_actions.md new file mode 100644 index 000000000..37204261d --- /dev/null +++ b/guides/advanced_index_actions.md @@ -0,0 +1,91 @@ +# Advanced Index Actions +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`: +```javascript +const { Client } = require('@opensearch-project/opensearch'); +const client = new Client({ + node: 'https://admin:admin@localhost:9200', + ssl: { rejectUnauthorized: 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: + +```javascript +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: + +```javascript +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: + +```javascript +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: + +```javascript +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: + +```javascript +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: + +```javascript +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: + +```javascript +client.indices.add_block({index: 'movies', block: 'write'}) +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: + +```javascript +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: +```javascript +client.indices.delete({index: ['movies', 'books', 'movies_clone', 'bigger_books']}); +``` \ No newline at end of file From 1988d752262f5190e4aecc533d92ba934d5b6002 Mon Sep 17 00:00:00 2001 From: Alexei Karikov <karikov.alist.ru@gmail.com> Date: Tue, 11 Apr 2023 00:34:46 +0600 Subject: [PATCH 2/2] Check linkchecker solving Signed-off-by: Alexei Karikov <karikov.alist.ru@gmail.com> --- guides/advanced_index_actions.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/guides/advanced_index_actions.md b/guides/advanced_index_actions.md index 37204261d..faf5dc43d 100644 --- a/guides/advanced_index_actions.md +++ b/guides/advanced_index_actions.md @@ -61,7 +61,7 @@ You can clone an index to create a new index with the same mappings, data, and M ```javascript client.indices.add_block({index: 'movies', block: 'write'}) client.indices.clone({index: 'movies', target: 'movies_clone'}) -client.indices.put_settings({index: 'movies', body: { index: { blocks: { write: false } } }}) +client.indices.put_settings({index: 'movies', body: { index: { blocks: { write: false } } } }) ``` ### Split index