# OpenSearch retention: how a policy deletes vulnerability state

> An ISM policy with a delete action on the wazuh-states-* pattern can empty vulnerability state indices. How to check the policy assignment and design retention.

Published: 2026-10-20. Category: Configuration. Tags: Wazuh 4. URL: https://wazuh.blog/en/blog/opensearch-retention/ Polish original: https://wazuh.blog/blog/opensearch-retencja/

A retention policy for event indices does not always suit indices that represent current state. This distinction hides a risk of losing vulnerability visibility.

## A typical scenario

The vulnerability state and inventory indices (`wazuh-states-vulnerabilities-<cluster>` and related ones) are suddenly empty, although they held data before. The configuration has an ISM policy, for example `example-events-retention`, assigned to the `wazuh-states-*` pattern and deleting the index after 30 days.

Such a setup justifies checking the index state, the policy and the ISM history, but on its own it does not identify the culprit or the time of the operation. Tell apart an index that is absent, one that exists without documents, and one that holds documents not visible in the query you use. These are different observations and need separate findings.

Before the analysis, check the actual index names and matching rules. Do not assume that every installation has a default ISM retention policy, or that a familiar pattern covers data of only one type.

## Two different data models

An alert index is usually a stream of events: an old document can be deleted according to the retention period. A state index answers the question "what is vulnerable right now?". The behavior after a state index is deleted depends on the version and configuration, so before deleting, check it on documentation.wazuh.com for the version you use.

This distinction should come before setting the retention period. For an event stream, deleting the oldest data can be an intended limit on history. For an index describing state, the same action can remove the current view that the user expects for review and triage. Index age and document age are separate concepts, and the `min_index_age` condition refers to index age. The difference between archives and alerts data in Wazuh is covered in the [post on archives and alerts](/en/blog/wazuh-archives-vs-alerts/).

## How ISM takes action

An ISM policy is a document describing index states, the actions run on entering a state, and the transitions to subsequent states. Each index managed by a policy is in exactly one state. Actions in a state run sequentially, and transition conditions are checked after the actions finish. If a state has no further transitions, the policy considers management finished.

A transition into a state does not itself run the target action. ISM checks the conditions after the actions of the current state finish, and then runs the actions of the state the index moves to.

ISM evaluates transitions in the order written in the policy and picks the first one whose condition is met. So the analysis should cover the `min_index_age` condition, the name of the target state and the actions assigned to that state.

ISM checks conditions when the managed index job runs. The default interval is 5 minutes, so an age threshold does not mean execution at the exact moment a given time is reached. The interval is set by the cluster setting `plugins.index_state_management.job_interval`.

| Policy element | Role |
| --- | --- |
| `default_state` | Initial state for an index managed by the policy |
| `actions` | Operations run in order after entering a state |
| `transitions` | Conditions for choosing the next state after the actions finish |
| `ism_template` | Automatic assignment of the policy to new indices matching a pattern |

Transition conditions cover more than index age.

| Condition | What it checks |
| --- | --- |
| `min_index_age` | Minimum index age |
| `min_rollover_age` | Minimum age after a rollover |
| `min_state_age` | Minimum time in the current state |
| `min_doc_count` | Minimum number of documents |
| `min_size` | Size of primary shards without replicas |
| `no_alias` | Whether the index has no aliases or has at least one alias |

## Policy assignment and match scope

A policy can reach an index in two ways. `ism_template` automatically applies it to newly created indices whose names match `index_patterns`. When more than one template matches a new index, `priority` is used to pick the policy. Such a template does not apply retroactively to indices that already existed when it was created.

You can put an existing index under a policy with the ISM add API:

```http
POST _plugins/_ism/add/example-events-000001
{
  "policy_id": "example-events-retention"
}
```

Adding does not overwrite a policy that is already assigned. An HTTP 200 response does not prove that every index in the request was updated: the documentation describes a response with `failures` and `failed_indices` for failed items.

The `*` wildcard in the add API can cover all indices, including system indices that store users, roles and tenants. A policy with a delete action applied with such a scope can lead to the deletion of system data. Limit the scope to a specific, verified prefix and check which indices actually match before the change. The pattern name alone is no protection against a wrong match. For `ism_template`, check all matching templates and their priorities, because ISM picks the template with the highest priority for a newly created index. Checking only one policy can miss a competing match.

## Diagnostics without changes

Changing the policy of an already managed index requires the Update managed index policy API. The definition change takes effect at the next policy run, and until then the index can use a cached version. The `if_seq_no` and `if_primary_term` parameters must match the current policy version. Compare the definition assigned to the index with the current policy document before drawing conclusions from its modification.

Read-only first: ISM policies, assignments to indices, job history, templates, document counts and logs. Do not run mass reindexing, change policies or attach another one without establishing the scope of impact and a way to restore the state. Record index names, their presence and document counts as separate observations. Then establish whether the index is managed, which policy is attached to it, and whether the policy version assigned to the index matches the current policy document.

You can check the policy and its application to an index separately:

```http
GET _plugins/_ism/explain/example-events-000001?show_policy=true
GET _plugins/_ism/policies/example-events-retention
```

The `show_policy=true` parameter shows the policy version currently applied to the index. `GET _plugins/_ism/policies/{policy_id}` fetches the current definition. Comparing these responses shows the difference between the version assigned to the index and the latest definition.

After a policy is added, the Explain index response can initially contain `null` fields and `total_managed_indices` equal to `0`, because the index job is created at the next ISM run. Do not treat such a response right after assignment as proof that the index was definitely not put under management. Read the state again after the job runs.

Deleting a policy immediately stops index management and cannot be undone.

## Action errors and rollover

Not every policy is only about deletion. The rollover action requires the index setting `rollover_alias`. When the setting is missing, Explain index can contain a `validation_message` about `Missing rollover_alias index setting`, if validation was enabled through `plugins.index_state_management.action_validation.enabled`. With such an error, first assess the rollover configuration and the management state, and do not assume the transition to the next state happened.

A timeout covers the whole action, including retries and pauses between job runs. After a failure, ISM stops managing the index until the Retry failed index API is called. A timeout does not undo changes already made or stop work already started. Before retrying, check in Explain index that `action.failed` is `true` and `step.step_status` is `failed`. Retry runs the failed action again, so allow for a partial effect of the earlier attempt.

## Designing retention

Choose retention to fit the data semantics: they decide whether deleting older data matches the retention goal.

| Data type | Semantics | Question before setting retention |
| --- | --- | --- |
| `alerts` | Event stream | Does deleting older events match the required history period? |
| `states` | Current state | Has the source behavior after index deletion been verified for the Wazuh version in use? |

The example below creates an ISM policy for new indices matching `example-events-*`. The policy starts in the `active` state, and the age condition leads to the `delete` state, whose action is deleting the index. Names starting with `example-` and the value `30d` are a synthetic illustration, not a recommended retention period.

```http
PUT _plugins/_ism/policies/example-events-retention

{
  "policy": {
    "description": "Illustrative retention for example event indexes",
    "default_state": "active",
    "states": [
      {
        "name": "active",
        "actions": [],
        "transitions": [
          {
            "state_name": "delete",
            "conditions": {
              "min_index_age": "30d"
            }
          }
        ]
      },
      {
        "name": "delete",
        "actions": [
          {
            "delete": {}
          }
        ],
        "transitions": []
      }
    ],
    "ism_template": [
      {
        "index_patterns": ["example-events-*"],
        "priority": 1
      }
    ]
  }
}
```

Before applying a policy to an existing index, check its current assignment. Analyze the pattern, priority, age condition and the action in the target state together, so that the assignment scope matches the kind of data.

| Index state | Assignment or change mechanism |
| --- | --- |
| New index matching a pattern | `ism_template`, with selection by `priority` |
| Existing index without a policy | `POST _plugins/_ism/add/{index}` |
| Index already managed | Update managed index policy API |

Do not move the `example-*` pattern from event indices to state indices without checking the data semantics and the source behavior after index deletion.

## Interpreting the findings

A policy matching a pattern does not confirm that the action ran. Assigning a cause requires agreement between the index name, the time and the trace of the ISM job. A policy that deletes an index does not describe whether another operation deleted the documents earlier. In the report, record for each name: index presence, document count, attached policy, current state, matching pattern, target state and action result. Mark missing history or administrative logs as a limit of the finding. The cause remains undetermined if the observations do not link a specific action to a specific index.

## Sources

- https://docs.opensearch.org/latest/im-plugin/ism/policies/
- https://docs.opensearch.org/latest/im-plugin/ism/api/
