How to limit index size?

Hi all,

I was wondering if there is any way to prevent an index from crossing certain byte size limit (say 10GB). I tried to create an index policy as shown below, however it does not get executed immediately. In fact the index was closed after hitting 8mb!

Appreciate your suggestions.

PUT _plugins/_ism/policies/hp3
{
“policy”: {
“description”: “a policy to close an index after it crosses 1mb”,
“default_state”: “hot”,
“schema_version”: 1,
“states”: [
{
“name”: “hot”,
“actions”: ,
“transitions”: [
{
“state_name”: “close”,
“conditions”: {
“min_size”: “1mb”
}
}
]
},
{
“name”: “close”,
“actions”: [
{
“close”: {
}
}
]
}
],
“ism_template”: {
“index_patterns”: [“test_index*”],
“priority”: 0
}
}
}

POST _plugins/_ism/add/test_index*
{
“policy_id”: “hp3”
}

Hey @asfoorial

Have you tried changing your “priority”: 0 to something like “priority”: 100?

I tried. The same… the index status shows “Still initializing, please wait a moment”. Infact the transition did not trigger until I stopped indexing! My object is to prevent indexing tasks from flooding the environment and going beyond certain predefined threshold.

hey,

when that happens I would tail -f opensearch/opensearch-dashboard log file’s, see if you can find anything that pertains to this issue. Sometime when the index set is in RED this could happen .

It is not in RED state but rather yellow due to replication. Again my objective is to prevent going beyond storage threshold for a particular index, is that possible with really building an external monitoring solution?

Hey @asfoorial

I get it, sometime when messing with Policys it doesnt work well when a index set is not in a Green state.
I think your looking for something like this

{
    "id": "something",
    "seqNo": 6192,
    "primaryTerm": 16,
    "policy": {
        "policy_id": "something",
        "description": "testing",
        "last_updated_time": 1708402901021,
        "schema_version": 19,
        "error_notification": null,
        "default_state": "hot",
        "states": [
            {
                "name": "hot",
                "actions": [],
                "transitions": [
                    {
                        "state_name": "close",
                        "conditions": {
                            "min_size": "1mb"
                        }
                    }
                ]
            },
            {
                "name": "close",
                "actions": [
                    {
                        "retry": {
                            "count": 3,
                            "backoff": "exponential",
                            "delay": "1m"
                        },
                        "close": {}
                    }
                ],
                "transitions": []
            },
            {
                "name": "delete",
                "actions": [
                    {
                        "retry": {
                            "count": 3,
                            "backoff": "exponential",
                            "delay": "1m"
                        },
                        "delete": {}
                    }
                ],
                "transitions": []
            }
        ],
        "ism_template": [
            {
                "index_patterns": [
                    "security"
                ],
                "priority": 200,
                "last_updated_time": 1708402712551
            }
        ]
    }
}

Insted of using the Dev tools try to use the dashbaord visual editor. if its not correct it will error out.

Edit: Or something like this

{
    "id": "a policy to close an index after it crosses 1mb",
    "seqNo": 6139,
    "primaryTerm": 16,
    "policy": {
        "policy_id": "a policy to close an index after it crosses 1mb",
        "description": "a policy to close an index after it crosses 1mb",
        "last_updated_time": 1708400771608,
        "schema_version": 19,
        "error_notification": null,
        "default_state": "hot",
        "states": [
            {
                "name": "hot",
                "actions": [
                    {
                        "retry": {
                            "count": 3,
                            "backoff": "exponential",
                            "delay": "1m"
                        },
                        "rollover": {
                            "min_size": "1mb",
                            "copy_alias": false
                        }
                    },
                    {
                        "retry": {
                            "count": 3,
                            "backoff": "exponential",
                            "delay": "1m"
                        },
                        "close": {}
                    },
                    {
                        "retry": {
                            "count": 3,
                            "backoff": "exponential",
                            "delay": "1m"
                        },
                        "delete": {}
                    }
                ],
                "transitions": []
            }
        ],
        "ism_template": [
            {
                "index_patterns": [
                    "security"
                ],
                "priority": 100,
                "last_updated_time": 1708400248905
            }
        ]
    }
}

I havent got chance to test it but I think you get the point