liveBook · Manning

Retention policy

As explained in Elasticsearch in Action, Second Edition

A snapshot retention policy specifies the conditions and duration governing how long snapshots remain available.

A snapshot retention policy controls how long automated snapshots remain available. For example, nightly backups of movie indexes can be retained for one week before expiration. section 14.4.6

Within snapshot lifecycle management, the retention setting works with a schedule, repository, and selected indexes. The policy is stored in the cluster and runs when its schedule triggers. section 14.4.6

Keep nightly snapshots for seven days

Set the retention value to "7d" in an SLM policy that backs up indexes matching "*movies*" and "*reviews*". A midnight schedule creates a new dated snapshot each night; expired snapshots are governed by the seven-day setting. section 14.4.6

Listing 14.11 Creating a policy for scheduled snapshots
PUT _slm/policy/prod_cluster_daily_backups         #1
{
  "name":"<prod_daily_backups-{now/d}>",           #2
  "schedule": "0 0 0 * * ?",                       #3
  "repository": "es_cluster_snapshot_repository",  #4
  "config": { 
    "indices":["*movies*", "*reviews*"],           #5
    "include_global_state": false                  #6
  },
  "retention":{
    "Expire_after":"7d"                            #7
  }
}

Inspect the complete _slm policy request, including the repository, selected indexes, schedule, and retention configuration. section 14.4.6

How Elasticsearch in Action, Second Edition covers it

How deep it goes
Defines retention as a duration and demonstrates a seven-day JSON setting, without detailing expiration internals.
Examples
Uses midnight backups of movie and review indexes with date-based names and seven-day expiration.
What it assumes
Requires a registered snapshot repository before configuring snapshot lifecycle management.
What you can do after
Operate/configure retention through the Elasticsearch _slm API and a policy JSON request.
How it connects
Connects snapshot retention with snapshot lifecycle management, snapshots, repositories, schedules, and indexes.

Also explained in

Compare how 10 books explain retention policy →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Elasticsearch in Action, Second Edition. The section links point to the parts of the book it draws on.