Create or update a policy Generally available; Added in 7.4.0

PUT /_slm/policy/{policy_id}

Create or update a snapshot lifecycle policy. If the policy already exists, this request increments the policy version. Only the latest version of a policy is stored.

Required authorization

  • Index privileges: manage
  • Cluster privileges: manage_slm

Path parameters

  • policy_id string Required

    The identifier for the snapshot lifecycle policy you want to create or update.

Query parameters

  • master_timeout string

    The period to wait for a connection to the master node. If no response is received before the timeout expires, the request fails and returns an error. To indicate that the request should never timeout, set it to -1.

    Values are -1 or 0.

  • timeout string

    The period to wait for a response. If no response is received before the timeout expires, the request fails and returns an error. To indicate that the request should never timeout, set it to -1.

    Values are -1 or 0.

application/json

Body

  • config object

    Configuration for each snapshot created by the policy.

    Hide config attributes Show config attributes object
    • ignore_unavailable boolean

      If false, the snapshot fails if any data stream or index in indices is missing or closed. If true, the snapshot ignores missing or closed data streams and indices.

      Default value is false.

    • indices string | array[string]

      A comma-separated list of data streams and indices to include in the snapshot. Multi-index syntax is supported. By default, a snapshot includes all data streams and indices in the cluster. If this argument is provided, the snapshot only includes the specified data streams and clusters.

    • include_global_state boolean

      If true, the current global state is included in the snapshot.

      Default value is true.

    • feature_states array[string]

      A list of feature states to be included in this snapshot. A list of features available for inclusion in the snapshot and their descriptions be can be retrieved using the get features API. Each feature state includes one or more system indices containing data necessary for the function of that feature. Providing an empty array will include no feature states in the snapshot, regardless of the value of include_global_state. By default, all available feature states will be included in the snapshot if include_global_state is true, or no feature states if include_global_state is false.

    • metadata object

      Attaches arbitrary metadata to the snapshot, such as a record of who took the snapshot, why it was taken, or any other useful data. Metadata must be less than 1024 bytes.

      Hide metadata attribute Show metadata attribute object
      • * object Additional properties
    • partial boolean

      If false, the entire snapshot will fail if one or more indices included in the snapshot do not have all primary shards available.

      Default value is false.

  • name string

    Name automatically assigned to each snapshot created by the policy. Date math is supported. To prevent conflicting snapshot names, a UUID is automatically appended to each snapshot name.

  • repository string

    Repository used to store snapshots created by this policy. This repository must exist prior to the policy’s creation. You can create a repository using the snapshot repository API.

  • retention object

    Retention rules used to retain and delete snapshots created by the policy.

    Hide retention attributes Show retention attributes object
    • expire_after string Required

      Time period after which a snapshot is considered expired and eligible for deletion. SLM deletes expired snapshots based on the slm.retention_schedule.

    • max_count number Required

      Maximum number of snapshots to retain, even if the snapshots have not yet expired. If the number of snapshots in the repository exceeds this limit, the policy retains the most recent snapshots and deletes older snapshots.

    • min_count number Required

      Minimum number of snapshots to retain, even if the snapshots have expired.

  • schedule string

    Periodic or absolute schedule at which the policy creates snapshots. SLM applies schedule changes immediately.

Responses

  • 200 application/json
    Hide response attribute Show response attribute object
    • acknowledged boolean Required

      For a successful response, this value is always true. On failure, an exception is returned instead.

PUT /_slm/policy/daily-snapshots
{
  "schedule": "0 30 1 * * ?",
  "name": "<daily-snap-{now/d}>",
  "repository": "my_repository",
  "config": {
    "indices": ["data-*", "important"],
    "ignore_unavailable": false,
    "include_global_state": false
  },
  "retention": {
    "expire_after": "30d",
    "min_count": 5,
    "max_count": 50
  }
}
resp = client.slm.put_lifecycle(
    policy_id="daily-snapshots",
    schedule="0 30 1 * * ?",
    name="<daily-snap-{now/d}>",
    repository="my_repository",
    config={
        "indices": [
            "data-*",
            "important"
        ],
        "ignore_unavailable": False,
        "include_global_state": False
    },
    retention={
        "expire_after": "30d",
        "min_count": 5,
        "max_count": 50
    },
)
const response = await client.slm.putLifecycle({
  policy_id: "daily-snapshots",
  schedule: "0 30 1 * * ?",
  name: "<daily-snap-{now/d}>",
  repository: "my_repository",
  config: {
    indices: ["data-*", "important"],
    ignore_unavailable: false,
    include_global_state: false,
  },
  retention: {
    expire_after: "30d",
    min_count: 5,
    max_count: 50,
  },
});
response = client.slm.put_lifecycle(
  policy_id: "daily-snapshots",
  body: {
    "schedule": "0 30 1 * * ?",
    "name": "<daily-snap-{now/d}>",
    "repository": "my_repository",
    "config": {
      "indices": [
        "data-*",
        "important"
      ],
      "ignore_unavailable": false,
      "include_global_state": false
    },
    "retention": {
      "expire_after": "30d",
      "min_count": 5,
      "max_count": 50
    }
  }
)
$resp = $client->slm()->putLifecycle([
    "policy_id" => "daily-snapshots",
    "body" => [
        "schedule" => "0 30 1 * * ?",
        "name" => "<daily-snap-{now/d}>",
        "repository" => "my_repository",
        "config" => [
            "indices" => array(
                "data-*",
                "important",
            ),
            "ignore_unavailable" => false,
            "include_global_state" => false,
        ],
        "retention" => [
            "expire_after" => "30d",
            "min_count" => 5,
            "max_count" => 50,
        ],
    ],
]);
curl -X PUT -H "Authorization: ApiKey $ELASTIC_API_KEY" -H "Content-Type: application/json" -d '{"schedule":"0 30 1 * * ?","name":"<daily-snap-{now/d}>","repository":"my_repository","config":{"indices":["data-*","important"],"ignore_unavailable":false,"include_global_state":false},"retention":{"expire_after":"30d","min_count":5,"max_count":50}}' "$ELASTICSEARCH_URL/_slm/policy/daily-snapshots"
client.slm().putLifecycle(p -> p
    .config(c -> c
        .ignoreUnavailable(false)
        .indices(List.of("data-*","important"))
        .includeGlobalState(false)
    )
    .name("<daily-snap-{now/d}>")
    .policyId("daily-snapshots")
    .repository("my_repository")
    .retention(r -> r
        .expireAfter(e -> e
            .time("30d")
        )
        .maxCount(50)
        .minCount(5)
    )
    .schedule("0 30 1 * * ?")
);
Request examples
Run `PUT /_slm/policy/daily-snapshots` to create a lifecycle policy. The `schedule` is when the snapshot should be taken, in this case, 1:30am daily. The `retention` details specify to: keep snapshots for 30 days; always keep at least 5 successful snapshots, even if they're more than 30 days old; keep no more than 50 successful snapshots, even if they're less than 30 days old.
{
  "schedule": "0 30 1 * * ?",
  "name": "<daily-snap-{now/d}>",
  "repository": "my_repository",
  "config": {
    "indices": ["data-*", "important"],
    "ignore_unavailable": false,
    "include_global_state": false
  },
  "retention": {
    "expire_after": "30d",
    "min_count": 5,
    "max_count": 50
  }
}
Run `PUT /_slm/policy/hourly-snapshots` to create a lifecycle policy that uses interval scheduling. It creates a snapshot once every hour. The first snapshot will be created one hour after the policy is modified, with subsequent snapshots every hour afterward.
{
  "schedule": "1h",
  "name": "<hourly-snap-{now/d}>",
  "repository": "my_repository",
  "config": {
    "indices": ["data-*", "important"]
  }
}