liveBook · Manning

_slm API

As explained in Elasticsearch in Action, Second Edition

The _slm API is Elasticsearch's interface for creating, managing, and executing snapshot lifecycle policies.

The _slm API automates recurring Elasticsearch snapshots by storing lifecycle policies in the cluster. A policy selects the repository and indexes to back up, defines when snapshots run, and controls retention. A registered snapshot repository is required before creating a policy. section 14.4.6

Nightly movie-index backups

PUT _slm/policy/prod_cluster_daily_backups creates a policy for snapshots at midnight. The name <prod_daily_backups-{now/d}> uses date math to generate a date-specific snapshot name; the cron expression runs at midnight; the repository stores the snapshot; the index patterns select movie and review indexes; and the seven-day retention setting expires older snapshots. To trigger the policy immediately, use POST _slm/policy/prod_cluster_daily_backups/_execute. 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
  }
}

Use the complete REST listing to inspect the policy name, schedule, repository, index patterns, global-state choice, and retention configuration together. section 14.4.6

How Elasticsearch in Action, Second Edition covers it

How deep it goes
Explains policy creation, date-math names, cron scheduling, index selection, retention, and manual execution.
Examples
Uses nightly backups of movie and review indexes, a date-based snapshot name, seven-day retention, and manual policy execution.
What it assumes
Requires a registered snapshot repository before creating a snapshot lifecycle policy.
What you can do after
Operate/configure scheduled snapshot backups and trigger a policy manually through REST.
How it connects
Connects snapshot lifecycle management with snapshots, repositories, cron schedules, date math, and snapshot restore.

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.