Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Retention

Stream indices (events, raw events, findings, metrics, active responses, AI assistant sessions and security audit logs) are data streams managed by Index State Management (ISM) policies shipped by the Setup plugin. These are Wazuh’s default policies: do not edit them, create a custom policy instead. Each policy has two states:

  • hot — runs a rollover action. The write index is closed and a new backing index is created once the index reaches 20 GB per primary shard (or 200,000,000 documents, whichever comes first).
  • delete — deletes the index. The hot state transitions to it once the policy’s deletion age has passed since the index rolled over.

The two conditions are chained, not independent: ISM evaluates a state’s transitions only after that state’s actions have completed. A backing index therefore becomes eligible for deletion only after it has rolled over, and the deletion age (min_rollover_age) is measured from that rollover, not from the creation of the index. Counting from the creation would delete a full index as soon as it rolled over, because it took longer than the deletion age to fill, and the history would drop to almost nothing at every rollover.

The AI assistant sessions and security audit log policies are the exception: they also roll over by age, so every index is created at the previous rollover and min_index_age, measured from the creation, is the retention.

The retention formula

time an event is kept = time until its index rolls over (up to the fill time) + deletion age

The deletion age is a floor, not a ceiling.

  • An event is kept for the deletion age after its index rolls over, so the history never drops below the deletion age at any moment, however fast indices fill. An event ingested just before a rollover is kept for the deletion age, and one ingested just after is kept for the fill time plus the deletion age.
  • At high ingest rates the shard fills quickly and the deletion age dominates: retention is about the deletion age.
  • At low ingest rates the fill time dominates: data is kept much longer than the number in the policy description suggests.

Per-stream values

Every stream rolls over at 20 GB per primary shard or 200,000,000 documents. Only the AI assistant sessions and security audit log policies add an age condition to the rollover itself: min_index_age: 1d and min_index_age: 30d. Their deletion age counts from the creation of the index; the other five count it from the rollover.

PolicyStreamsRolloverDeletion age (floor)
stream-events-policywazuh-events-v5-<category>20 GB / 200M docs1 day after the rollover
stream-raw-events-policywazuh-events-raw-v520 GB / 200M docs4 hours after the rollover
stream-findings-policywazuh-findings-v5-<category>20 GB / 200M docs90 days after the rollover
stream-metrics-policywazuh-metrics-*20 GB / 200M docs30 days after the rollover
stream-active-responses-policywazuh-active-responses20 GB / 200M docs3 days after the rollover
ai-assistant-sessions-policywazuh-ai-assistant-sessions1 day, or 20 GB / 200M docs7 days after the creation
security-auditlogs-policysecurity-auditlogs30 days, or 20 GB / 200M docs90 days after the creation

The AI assistant sessions and security audit log policies are the exception on purpose: a fixed retention only means something if indices roll over on a schedule, so those streams rotate by age. The audit log is also small, so without the monthly rollover it would never reach 20 GB and never be deleted. The other five rotate by volume.

Disk sizing

Stream templates use one primary shard per index and auto_expand_replicas: 0-1, so on any cluster of two or more nodes the on-disk cost doubles. The 200M document condition effectively never fires first — at ~1 KB per event that would be 200 GB on a shard that rolls at 20 GB.

Per active event category the cost is the write index (up to 20 GB) plus the rolled-over indices kept for the deletion age. Indices are deleted whole, so that is the ingest of the deletion age rounded up to a whole number of 20 GB indices, and at least one. The table uses the 1-day deletion age of stream-events-policy:

Events ingestActive categoriesFill timePrimaries (ceiling)With 1 replicaRetention
10 GB/day3~6 days~120 GB~240 GB1 to ~7 days
100 GB/day3~14 h~180 GB~360 GB1 to ~1.6 days
1 TB/day4~2 h~1.1 TB~2.2 TB1 to ~1.1 days
10 TB/day4~12 min~10 TB~20 TB~1 day

The ceiling is one deletion age of total event ingest plus up to 40 GB per active category (the write index and the rounding up to a whole index), doubled if a replica is allocated. A longer deletion age raises it in proportion: see Keeping data longer before you change it. Events have no unbounded-disk failure mode. What is unbounded on a quiet deployment is retention time, not disk.

Low-volume deployments retain data indefinitely

ISM never deletes a data stream’s write index, and below 20 GB per primary shard the stream never rolls over. On a low-volume deployment the events and raw events streams therefore retain their data indefinitely: the backing index stays in the hot state on the attempt_rollover step with condition_not_met, and the 1-day and 4-hour deletion ages never apply.

This is the designed behaviour — disk usage stays bounded — but it has a consequence worth stating plainly:

The deletion ages in these policies cannot be used as privacy or compliance statements. “Raw events are deleted 4 hours after the rollover” is only true of a deployment that fills 20 GB per primary shard. On a quiet deployment, raw events persist until the index rolls over or is removed by hand.

The same holds for findings, metrics and active responses. On a deployment that never fills a shard, findings are kept well past the 90-day deletion age. To delete them on a schedule, put an age condition on the rollover in a custom policy.

You can confirm what a given backing index is doing:

curl -sk -u admin:$WAZUH_INDEXER_ADMIN_PASSWORD \
  'https://localhost:9200/_plugins/_ism/explain/.ds-wazuh-events-v5-security-000001?pretty'

A response showing "step": {"name": "attempt_rollover", "step_status": "condition_not_met"} and "rolled_over": false means the index has not yet met a rollover condition and is not eligible for deletion.

Default policies

The seven policies above are Wazuh’s default policies. The Setup plugin indexes them by policy id whenever a node that has just started is elected cluster manager, which includes a full restart and every upgrade, so the policies a new release ships always reach the deployment. Each write overwrites whatever is stored under that id: an edit made to a default policy, through the ISM API or the dashboard, is reverted on the next full restart or upgrade. ISM cannot mark a policy as read-only, so nothing stops the edit in the first place.

Do not edit the default policies. To change retention, create a custom policy instead. The Setup plugin only ever writes its own seven policy ids, so a policy stored under any other id is never touched.

Existing indices keep the policy version they started with

Each managed index runs on its own copy of the policy, taken when the index was attached to it and returned by the explain API with ?show_policy=true. Storing a new version of the policy, whether by an edit, a restart or an upgrade, changes neither that copy nor the retention of the indices already managed. Only backing indices created afterwards start on the new version. This has two consequences:

  • A retention change applies to the existing indices only once you move them with change_policy, as shown in Creating a custom policy.
  • After an upgrade that ships a new version of a default policy, the existing backing indices keep running the old version. On a low-volume deployment the write index never rolls over, so it can run the old version indefinitely.

To see which version each index runs, compare the last_updated_time of the stored policy with the one in the copy each index runs:

curl -sk -u admin:$WAZUH_INDEXER_ADMIN_PASSWORD \
  'https://localhost:9200/_plugins/_ism/policies/stream-findings-policy' | jq '.policy.last_updated_time'

curl -sk -u admin:$WAZUH_INDEXER_ADMIN_PASSWORD \
  'https://localhost:9200/_plugins/_ism/explain/.ds-wazuh-findings-v5-*?show_policy=true' \
  | jq -r 'to_entries[] | select(.value | type == "object") | [.key, .value.policy_id, .value.policy.last_updated_time] | @tsv'

The Setup plugin writes the last_updated_time shipped with the release, so it changes only when a release changes the policy, and an index with an older value runs an older version. An edit through the ISM API or the dashboard sets it to the time of the edit. Do not compare the _seq_no of the policy with the policy_seq_no of the index: every restart rewrites the default policies and raises their _seq_no even when their content does not change.

To move the existing indices onto the current version of a policy, run change_policy with the same policy id, then verify the switch as described in step 4 of Creating a custom policy. The same restart warning applies:

curl -sk -u admin:$WAZUH_INDEXER_ADMIN_PASSWORD -X POST \
  'https://localhost:9200/_plugins/_ism/change_policy/.ds-wazuh-findings-v5-*' \
  -H 'Content-Type: application/json' -d '{"policy_id": "stream-findings-policy"}'

Creating a custom policy

ISM cannot clone a policy, so a custom policy starts as a copy of the default one. The steps below delete findings 30 days after their backing index is created, on any deployment, including those that never fill a shard. The same steps apply to any other stream: use its policy and index patterns from the per-stream table. The commands use jq.

1. Copy the default policy and change the copy. Two changes set the retention, and a third makes the policy win over the default one:

  • min_index_age on the rollover action makes the write index roll over daily, so it becomes eligible for deletion even when it never fills a shard. Keep it shorter than the deletion age.
  • min_index_age on the transition to delete is the deletion age, measured from index creation. It replaces the default policy’s min_rollover_age, because a transition takes a single condition.
  • priority: 1 in the ism_template makes ISM attach new backing indices to this policy instead of the default one (priority: 0).
curl -sk -u admin:$WAZUH_INDEXER_ADMIN_PASSWORD \
  'https://localhost:9200/_plugins/_ism/policies/stream-findings-policy' \
  | jq '{policy: (.policy
      | del(.policy_id, .last_updated_time, .schema_version, .error_notification)
      | .description = "Custom findings policy: deletes findings 30 days after their backing index is created."
      | .states[0].actions[0].rollover.min_index_age = "1d"
      | .states[0].transitions[0].conditions = {"min_index_age": "30d"}
      | .ism_template[].priority = 1)}' > custom-findings-policy.json

Review custom-findings-policy.json before going further.

2. Store the copy under its own policy id.

curl -sk -u admin:$WAZUH_INDEXER_ADMIN_PASSWORD -X PUT \
  'https://localhost:9200/_plugins/_ism/policies/custom-findings-policy' \
  -H 'Content-Type: application/json' -d @custom-findings-policy.json

From now on, new findings backing indices are attached to custom-findings-policy. Their index.plugins.index_state_management.policy_id setting still names the default policy, because the index template sets it: the policy_id that the explain API reports is the one ISM runs.

3. Move the existing indices onto it. The ism_template applies only to indices created from now on, and the existing ones keep the policy they started with:

curl -sk -u admin:$WAZUH_INDEXER_ADMIN_PASSWORD -X POST \
  'https://localhost:9200/_plugins/_ism/change_policy/.ds-wazuh-findings-v5-*' \
  -H 'Content-Type: application/json' -d '{"policy_id": "custom-findings-policy"}'

4. Wait for the change to apply, and verify it. change_policy is asynchronous: the response lists the indices it queued, not the indices it changed. Each index switches on its next ISM run (every 5 minutes by default) and reports Attempting to change policy to custom-findings-policy until the following run resumes the policy, so the switch can take two runs or more. It is complete when every index reports the new policy_id and a step name:

curl -sk -u admin:$WAZUH_INDEXER_ADMIN_PASSWORD \
  'https://localhost:9200/_plugins/_ism/explain/.ds-wazuh-findings-v5-*' \
  | jq -r 'to_entries[] | select(.value | type == "object") | [.key, .value.policy_id, (.value.step.name // "pending")] | @tsv'

Do not restart the cluster until every index has switched. A pending change survives a restart, but an index whose ISM run is interrupted while it switches stays on Attempting to change policy to <policy_id> for about an hour, then fails with There is a version conflict between your previous execution and your managed index and is no longer managed, so none of its retention applies. To list the indices in that state:

curl -sk -u admin:$WAZUH_INDEXER_ADMIN_PASSWORD \
  'https://localhost:9200/_plugins/_ism/explain/.ds-wazuh-findings-v5-*' \
  | jq -r 'to_entries[] | select(.value | type == "object") | select(.value.retry_info.failed == true) | [.key, .value.policy_id, .value.info.message] | @tsv'

_plugins/_ism/retry and a new change_policy do not fix such an index. Remove the policy from it and add it back, with the policy you were moving it to as <policy_id>:

curl -sk -u admin:$WAZUH_INDEXER_ADMIN_PASSWORD -X POST \
  'https://localhost:9200/_plugins/_ism/remove/<index>'

curl -sk -u admin:$WAZUH_INDEXER_ADMIN_PASSWORD -X POST \
  'https://localhost:9200/_plugins/_ism/add/<index>' \
  -H 'Content-Type: application/json' -d '{"policy_id": "<policy_id>"}'

To go back to the default retention, run step 3 with "policy_id": "stream-findings-policy", wait for the switch as in step 4 (the restart warning applies here too), then delete custom-findings-policy.

Weigh two trade-offs before you shorten retention this way:

  • More indices, more shards. Rolling over on a schedule on a quiet deployment produces many small backing indices, each with its own shard overhead.
  • Data loss relative to today. A deployment that currently keeps months of data inside a single 20 GB shard starts deleting it at the age you choose, existing data included once step 3 applies.

In a policy that rolls over by age, as in this example, keep min_index_age in the transition. min_rollover_age would stack the retention window on top of an already-full generation, which costs more disk at exactly the ingest rates where disk matters. The default policies of the streams that roll over by volume use min_rollover_age on purpose, so that the previous index is kept for the whole deletion age after it rolled over.

Keeping data longer

To keep a stream longer without changing when it rolls over, for example to keep events for a weekend investigation window, change only the deletion age and leave the rollover and min_rollover_age as they are. The copy in step 1 then looks like this, for 3 days of events:

curl -sk -u admin:$WAZUH_INDEXER_ADMIN_PASSWORD \
  'https://localhost:9200/_plugins/_ism/policies/stream-events-policy' \
  | jq '{policy: (.policy
      | del(.policy_id, .last_updated_time, .schema_version, .error_notification)
      | .description = "Custom events policy: deletes events 3 days after their backing index rolled over."
      | .states[0].transitions[0].conditions.min_rollover_age = "3d"
      | .ism_template[].priority = 1)}' > custom-events-policy.json

Then follow steps 2 to 4 with custom-events-policy as the policy id and .ds-wazuh-events-v5-* as the index pattern. The disk it needs grows with the deletion age, as the Disk sizing table shows: size the nodes for it before you apply the policy.