Files
opensearch-pyd/guides/plugins/index_management.md
T
Daniel (dB.) Doubrovkine 58217d98ff Reorganize documentation and add samples. (#447)
Signed-off-by: dblock <dblock@amazon.com>
2023-07-24 10:23:51 -07:00

2.0 KiB

Index Management Plugin

You can use the Index Management Plugin (ISM) API to programmatically automate periodic, administrative operations on indexes by triggering them based on changes in the index age, index size, or number of documents.

Create a Policy

policy_name = "test-policy"

policy_content = {
    "policy": {
        "description": "hot warm delete workflow",
        "default_state": "hot",
        "schema_version": 1,
        "states": [
            {
                "name": "hot",
                "actions": [{"rollover": {"min_index_age": "1d"}}],
                "transitions": [{"state_name": "warm"}],
            },
            {
                "name": "warm",
                "actions": [{"replica_count": {"number_of_replicas": 5}}],
                "transitions": [{"state_name": "delete", "conditions": {"min_index_age": "30d"}}],
            },
            {
                "name": "delete",
                "actions": [
                    {
                        "notification": {
                            "destination": {"chime": {"url": "<URL>"}},
                            "message_template": {"source": "The index {{ctx.index}} is being deleted"},
                        }
                    },
                    {"delete": {}},
                ],
            },
        ],
        "ism_template": {"index_patterns": ["log*"], "priority": 100},
    }
}

response = client.index_managment.put_policy(policy_name, body=policy_content)
print(response)

Get a Policy

policy_name = "test-policy"

response = client.index_managment.get_policy(policy_name)
print(response)

Delete a Policy

policy_name = "test-policy"

response = client.index_managment.delete_policy(policy_name)
print(response)