Index Lifecycle Management
Scenario
Based on the time management, you can periodically perform some operations on the old index (for example, reducing the number of replicas or deleting the index) to ensure that there are sufficient resources in the cluster. The index life cycle management plug-in allows users to periodically trigger management operations based on the index existence time, size, and document quantity to implement automatic management.
Basic Concepts |
Description |
---|---|
policy |
Policy defined in the index lifecycle. |
states |
Current status of an index, for example, hot or cold. |
actions |
Actions to be performed in sequence when a policy enters a certain state. |
conditions |
Conditions that need to be met for state transition. |
Common Policy Commands
Common Operation |
Command |
---|---|
View the policy_1 content. |
GET _opendistro/_ism/policies/policy_1 |
Delete the index_1 policy. |
POST _opendistro/_ism/remove/index_1 |
Modifying the index_1 policy. |
POST _opendistro/_ism/change_policy/index_1 |
Retry index_1 in the close status. |
POST _opendistro/_ism/retry/index_1 { "state": "close" } |
Check the execution of the policy in index_1. |
GET _opendistro/_ism/explain/index_1 |
Delete policy_1. |
DELETE _opendistro/_ism/policies/policy_1 |
List of Supported Actions
Action |
Function |
Notice |
---|---|---|
rollover |
Generates indexes based on the preset number of documents, index age, and index size. |
The name of the rollover index must meet the ^.*-\d+$ regular expression, for example, logs-000001. You need to set an alias for the index, set is_write_index to true, and set opendistro.index_state_management.rollover_alias to the alias. |
open |
Opens indexes. |
- |
close |
Closes indexes. |
- |
read_only |
Sets an index to read-only state. |
- |
read_write |
Restores the index to the writable state. |
- |
replica_count |
Reduces the number of copies. |
- |
index_priority |
Sets the recovery priority of an index. A larger value indicates a higher priority. |
- |
freeze_index |
Sets an index to the frozen state. |
- |
unfreeze_index |
Unfreezes an index. |
- |
allocation |
Migrates cold indexes to cold instances to separate cold and hot indexes. |
|
shrink |
Reduces the number of primary shards of an index. |
The shrink action migrates all primary shards to the same instance. Ensure that the instance disk where the shard of an index is located has sufficient space. The number of primary shards to be reduced must be a factor of the total number of source index shards. For example, an index of eight primary shards can be reduced to four, two, or one primary shard. If the number of primary shards is a prime number, only one primary shard can be reduced. After the shrink action is performed successfully, the index name is changed to shrink-original index name. The original index name is used as the alias of the index after shrinking. (Not recommended) |
snapshot |
Creates a snapshot for an index. |
Before creating a snapshot, you need to create a repository. This action is not recommended. |
force_merge |
Merges segments of an index. |
It takes a long time to merge segments in the case of a large amount of data. Therefore, this action is not recommended. |
delete |
Deletes an index. |
If the deletion operation is incorrectly configured, data may be deleted by mistake. Therefore, exercise caution when performing this operation. |
For details about the ISM function of the open-source open distro plug-in, see https://opendistro.github.io/for-elasticsearch-docs/docs/ism/.
Common Condition Parameters
Parameter |
Description |
Type |
---|---|---|
min_index_age |
Optional. At least how long an index has been created before a conversion can be triggered. |
string |
min_doc_count |
Optional. At least how many documents have been contained in an index before a conversion can be triggered. |
number |
min_size |
Optional. Minimum storage space for the total number of primary shards (excluding replicas) in an index that can trigger a conversion. For example, if min_size is set to 100 GB, the index has five primary and five replica shards, and each shard is 20 GB, the total size of all primary shards is 100 GB. Therefore, the index converts to a next state. |
string |
min_step_age |
Optional. Duration for switching to the next state after the previous state ends. |
string |
Example
- Create a policy.
PUT _opendistro/_ism/policies/default_policy { "policy":{ "description":"this policy is for all action.", "default_state":"hot", "states":[ { "name":"hot", "actions":[ { "index_priority":{ "priority":10 } }, { "rollover":{ "min_size":"1tb", "min_doc_count":"1000000000", "min_index_age":"1d" } } ], "transitions":[ { "state_name":"warm", "conditions":{ "min_index_age":"15d" } } ] }, { "name":"warm", "actions":[ { "index_priority":{ "priority":5 } }, { "read_only":{ } }, { "allocation":{ "require":{ "temperature":"warm" } } }, { "force_merge":{ "max_num_segments":1 } } ], "transitions":[ { "state_name":"cold", "conditions":{ "min_index_age":"60d" } } ] }, { "name":"cold", "actions":[ { "index_priority":{ "priority":1 } }, { "freeze_index":{ } }, { "shrink":{ "number_of_shards":10 } } ], "transitions":[ { "state_name":"close", "conditions":{ "min_index_age":"90d" } } ] }, { "name":"close", "actions":[ { "close":{ } } ] } ], "ism_template":{ "index_patterns":[ "indextest*" ], "priority":100 } } }
Bind the policy to the index.
After creating a policy, you need to apply the policy to an index or a group of indexes. You can also add the policy to the index template so that the policy can be applied to new indexes.
Specify the policy and alias when creating the first index.
PUT indextest-000001 { "settings": { "opendistro.index_state_management.policy_id": "policy_id", "opendistro.index_state_management.rollover_alias": "indextest" }, "aliases": { "indextest": { "is_write_index": true } } }
- If shrink is configured in the policy, set cluster.routing.allocation.same_shard.host to false to ensure that all shards can be migrated to one instance. Otherwise, the shrink operation cannot be performed.
You can run the following command to change the value of cluster.routing.allocation.same_shard.host:
PUT _cluster/settings{ "persistent": { "cluster.routing.allocation.same_shard.host":"false" }}
- If a rolling index is used, the index name must meet the regular expression of ^.*-\d+$.
- You need to create the first index that complies with the naming rules. The index alias can be used for subsequent write and query operations.
Add the policy to the index template.
PUT _template/<template_name> { "index_patterns": ["indextest*"], "settings": { "index.opendistro.index_state_management.policy_id": "policy_id", "index.opendistro.index_state_management.rollover_alias":"indextest" } }
- Set index_patterns based on the service scenario. Do not set index_patterns to *.
- The value of policy_id cannot contain special characters such as the number sign (#).
Run the following command to add the policy to the existing index in the cluster:
PUT /indextest-000001/_settings?pretty { "opendistro.index_state_management.policy_id": "policy_id", "opendistro.index_state_management.rollover_alias": "indextest" } POST /_aliases { "actions": [ { "add": { "index": "indextest-000001", "alias": "indextest", "is_write_index": true } } ] }
- The new policy can be scheduled only when the cluster is in the yellow or green state. If the cluster is in the red state, restore the indexes in the red state first.
- If a rolling index is used, the index name must meet the regular expression of ^.*-\d+$.
- If shrink is configured in the policy, set cluster.routing.allocation.same_shard.host to false to ensure that all shards can be migrated to one instance. Otherwise, the shrink operation cannot be performed.
Sample of Cold and Hot Separation Configuration
- Create a warm instance group.
Log in to FusionInsight Manager, choose Cluster > Name of the desired cluster > Services > Elasticsearch > Instance Groups, click under EsNodeX, set Group Name to warm, and click OK to create a warm instance group.
- Add instances to the instance group.
On the Basic tab page of EsNodeX, select the instance to be set to warm, click Move, set Target Instance Group to warm, and click OK to move the instance to the new warm instance group.
- Add the warm tag to the warm instances.
In the newly created warm instance group, choose Configuration > All Configurations > Hot-cold mode and set the value of node.attr.temperature to warm.
- Restart the warm instances.
After the instance of the warm group is restarted, the warm configuration takes effect.
Feedback
Was this page helpful?
Provide feedbackThank you very much for your feedback. We will continue working to improve the documentation.See the reply and handling status in My Cloud VOC.
For any further questions, feel free to contact us through the chatbot.
Chatbot