Policies

Policies are JSON documents that define the following:

  • The states that an index can be in, including the default state for new indices. For example, you might name your states “hot,” “warm,” “delete,” and so on. For more information, see States.
  • Any actions that you want the plugin to take when an index enters a state, such as performing a rollover. For more information, see Actions.
  • The conditions that must be met for an index to move into a new state, known as transitions. For example, if an index is more than eight weeks old, you might want to move it to the “delete” state. For more information, see Transitions.

In other words, a policy defines the states that an index can be in, the actions to perform when in a state, and the conditions that must be met to transition between states.

You have complete flexibility in the way you can design your policies. You can create any state, transition to any other state, and specify any number of actions in each state.

This table lists the relevant fields of a policy.

FieldDescriptionTypeRequiredRead Only
policy_idThe name of the policy.stringYesYes
descriptionA human-readable description of the policy.stringYesNo
ism_templateSpecify an ISM template pattern that matches the index to apply the policy.nested list of objectsNoNo
last_updated_timeThe time the policy was last updated.timestampYesYes
error_notificationThe destination and message template for error notifications. The destination could be Amazon Chime, Slack, or a webhook URL.objectNoNo
default_stateThe default starting state for each index that uses this policy.stringYesNo
statesThe states that you define in the policy.nested list of objectsYesNo

Table of contents

  1. States
  2. Actions
  3. ISM supported operations
    1. force_merge
    2. read_only
    3. read_write
    4. replica_count
    5. close
    6. open
    7. delete
    8. rollover
    9. notification
    10. snapshot
    11. index_priority
    12. allocation
  4. Transitions
  5. Error notifications
  6. Sample policy with ISM template
  7. Example policy

States

A state is the description of the status that the managed index is currently in. A managed index can be in only one state at a time. Each state has associated actions that are executed sequentially on entering a state and transitions that are checked after all the actions have been completed.

This table lists the parameters that you can define for a state.

FieldDescriptionTypeRequired
nameThe name of the state.stringYes
actionsThe actions to execute after entering a state. For more information, see Actions.nested list of objectsYes
transitionsThe next states and the conditions required to transition to those states. If no transitions exist, the policy assumes that it’s complete and can now stop managing the index. For more information, see Transitions.nested list of objectsYes

Actions

Actions are the steps that the policy sequentially executes on entering a specific state.

They are executed in the order in which they are defined.

This table lists the parameters that you can define for an action.

ParameterDescriptionTypeRequiredDefault
timeoutThe timeout period for the action. Accepts time units for minutes, hours, and days.time unitNo-
retryThe retry configuration for the action.objectNoSpecific to action

The retry operation has the following parameters:

ParameterDescriptionTypeRequiredDefault
countThe number of retry counts.numberYes-
backoffThe backoff policy type to use when retrying.stringNoExponential
delayThe time to wait between retries. Accepts time units for minutes, hours, and days.time unitNo1 minute

The following example action has a timeout period of one hour. The policy retries this action three times with an exponential backoff policy, with a delay of 10 minutes between each retry:

  1. "actions": {
  2. "timeout": "1h",
  3. "retry": {
  4. "count": 3,
  5. "backoff": "exponential",
  6. "delay": "10m"
  7. }
  8. }

For a list of available unit types, see Supported units.

ISM supported operations

ISM supports the following operations:

force_merge

Reduces the number of Lucene segments by merging the segments of individual shards. This operation attempts to set the index to a read-only state before starting the merging process.

ParameterDescriptionTypeRequired
max_num_segmentsThe number of segments to reduce the shard to.numberYes
  1. {
  2. "force_merge": {
  3. "max_num_segments": 1
  4. }
  5. }

read_only

Sets a managed index to be read only.

  1. {
  2. "read_only": {}
  3. }

read_write

Sets a managed index to be writeable.

  1. {
  2. "read_write": {}
  3. }

replica_count

Sets the number of replicas to assign to an index.

ParameterDescriptionTypeRequired
number_of_replicasDefines the number of replicas to assign to an index.numberYes
  1. {
  2. "replica_count": {
  3. "number_of_replicas": 2
  4. }
  5. }

For information about setting replicas, see Primary and replica shards.

close

Closes the managed index.

  1. {
  2. "close": {}
  3. }

Closed indices remain on disk, but consume no CPU or memory. You can’t read from, write to, or search closed indices.

Closing an index is a good option if you need to retain data for longer than you need to actively search it and have sufficient disk space on your data nodes. If you need to search the data again, reopening a closed index is simpler than restoring an index from a snapshot.

open

Opens a managed index.

  1. {
  2. "open": {}
  3. }

delete

Deletes a managed index.

  1. {
  2. "delete": {}
  3. }

rollover

Rolls an alias over to a new index when the managed index meets one of the rollover conditions.

The index format must match the pattern: ^.*-\d+$. For example, (logs-000001). Set index.plugins.index_state_management.rollover_alias as the alias to rollover.

ParameterDescriptionTypeExampleRequired
min_sizeThe minimum size of the total primary shard storage (not counting replicas) required to roll over the index. For example, if you set min_size to 100 GiB and your index has 5 primary shards and 5 replica shards of 20 GiB each, the total size of the primaries is 100 GiB, so the rollover occurs. ISM doesn’t check indices continually, so it doesn’t roll over indices at exactly 100 GiB. Instead, if an index is continuously growing, ISM might check it at 99 GiB, not perform the rollover, check again when the shards reach 105 GiB, and then perform the operation.string20gb or 5mbNo
min_doc_countThe minimum number of documents required to roll over the index.number2000000No
min_index_ageThe minimum age required to roll over the index. Index age is the time between its creation and the present.string5d or 7hNo
  1. {
  2. "rollover": {
  3. "min_size": "50gb"
  4. }
  5. }
  1. {
  2. "rollover": {
  3. "min_doc_count": 100000000
  4. }
  5. }
  1. {
  2. "rollover": {
  3. "min_index_age": "30d"
  4. }
  5. }

notification

Sends you a notification.

ParameterDescriptionTypeRequired
destinationThe destination URL.Slack, Amazon Chime, or webhook URLYes
message_templateThe text of the message. You can add variables to your messages using Mustache templates.objectYes

The destination system must return a response otherwise the notification operation throws an error.

Example 1: Chime notification

  1. {
  2. "notification": {
  3. "destination": {
  4. "chime": {
  5. "url": "<url>"
  6. }
  7. },
  8. "message_template": {
  9. "source": "the index is {{ctx.index}}"
  10. }
  11. }
  12. }

Example 2: Custom webhook notification

  1. {
  2. "notification": {
  3. "destination": {
  4. "custom_webhook": {
  5. "url": "https://<your_webhook>"
  6. }
  7. },
  8. "message_template": {
  9. "source": "the index is {{ctx.index}}"
  10. }
  11. }
  12. }

Example 3: Slack notification

  1. {
  2. "notification": {
  3. "destination": {
  4. "slack": {
  5. "url": "https://hooks.slack.com/services/xxx/xxxxxx"
  6. }
  7. },
  8. "message_template": {
  9. "source": "the index is {{ctx.index}}"
  10. }
  11. }
  12. }

You can use ctx variables in your message to represent a number of policy parameters based on the past executions of your policy. For example, if your policy has a rollover action, you can use {{ctx.action.name}} in your message to represent the name of the rollover.

The following ctx variable options are available for every policy:

Guaranteed variables

ParameterDescriptionType
indexThe name of the index.string
index_uuidThe uuid of the index.string
policy_idThe name of the policy.string

snapshot

Backup your cluster’s indices and state. For more information about snapshots, see Take and restore snapshots.

The snapshot operation has the following parameters:

ParameterDescriptionTypeRequiredDefault
repositoryThe repository name that you register through the native snapshot API operations.stringYes-
snapshotThe name of the snapshot.stringYes-
  1. {
  2. "snapshot": {
  3. "repository": "my_backup",
  4. "snapshot": "my_snapshot"
  5. }
  6. }

index_priority

Set the priority for the index in a specific state. Unallocated shards of indices are recovered in the order of their priority, whenever possible. The indices with higher priority values are recovered first followed by the indices with lower priority values.

The index_priority operation has the following parameter:

ParameterDescriptionTypeRequiredDefault
priorityThe priority for the index as soon as it enters a state.numberYes1
  1. "actions": [
  2. {
  3. "index_priority": {
  4. "priority": 50
  5. }
  6. }
  7. ]

allocation

Allocate the index to a node with a specific attribute. For example, setting require to warm moves your data only to “warm” nodes.

The allocation operation has the following parameters:

ParameterDescriptionTypeRequired
requireAllocate the index to a node with a specified attribute.stringYes
includeAllocate the index to a node with any of the specified attributes.stringYes
excludeDon’t allocate the index to a node with any of the specified attributes.stringYes
wait_forWait for the policy to execute before allocating the index to a node with a specified attribute.stringYes
  1. "actions": [
  2. {
  3. "allocation": {
  4. "require": { "box_type": "warm" }
  5. }
  6. }
  7. ]

Transitions

Transitions define the conditions that need to be met for a state to change. After all actions in the current state are completed, the policy starts checking the conditions for transitions.

Transitions are evaluated in the order in which they are defined. For example, if the conditions for the first transition are met, then this transition takes place and the rest of the transitions are dismissed.

If you don’t specify any conditions in a transition and leave it empty, then it’s assumed to be the equivalent of always true. This means that the policy transitions the index to this state the moment it checks.

This table lists the parameters you can define for transitions.

ParameterDescriptionTypeRequired
state_nameThe name of the state to transition to if the conditions are met.stringYes
conditionsList the conditions for the transition.listYes

The conditions object has the following parameters:

ParameterDescriptionTypeRequired
min_index_ageThe minimum age of the index required to transition.stringNo
min_doc_countThe minimum document count of the index required to transition.numberNo
min_sizeThe minimum size of the index required to transition.stringNo
cronThe cron job that triggers the transition if no other transition happens first.objectNo
cron.cron.expressionThe cron expression that triggers the transition.stringYes
cron.cron.timezoneThe timezone that triggers the transition.stringYes

The following example transitions the index to a cold state after a period of 30 days:

  1. "transitions": [
  2. {
  3. "state_name": "cold",
  4. "conditions": {
  5. "min_index_age": "30d"
  6. }
  7. }
  8. ]

ISM checks the conditions on every execution of the policy based on the set interval.

This example uses the cron condition to transition indices every Saturday at 5:00 PT:

  1. "transitions": [
  2. {
  3. "state_name": "cold",
  4. "conditions": {
  5. "cron": {
  6. "cron": {
  7. "expression": "* 17 * * SAT",
  8. "timezone": "America/Los_Angeles"
  9. }
  10. }
  11. }
  12. }
  13. ]

Note that this condition does not execute at exactly 5:00 PM; the job still executes based off the job_interval setting. Due to this variance in start time and the amount of time that it can take for actions to complete prior to checking transition conditions, we recommend against overly narrow cron expressions. For example, don’t use 15 17 * * SAT (5:15 PM on Saturday).

A window of an hour, which this example uses, is generally sufficient, but you might increase it to 2–3 hours to avoid missing the window and having to wait a week for the transition to occur. Alternately, you could use a broader expression such as * * * * SAT,SUN to have the transition occur at any time during the weekend.

For information on writing cron expressions, see Cron expression reference.


Error notifications

The error_notification operation sends you a notification if your managed index fails. It notifies a single destination with a custom message.

Set up error notifications at the policy level:

  1. {
  2. "policy": {
  3. "description": "hot warm delete workflow",
  4. "default_state": "hot",
  5. "schema_version": 1,
  6. "error_notification": { },
  7. "states": [ ]
  8. }
  9. }
ParameterDescriptionTypeRequired
destinationThe destination URL.Slack, Amazon Chime, or webhook URLYes
message_templateThe text of the message. You can add variables to your messages using Mustache templates.objectYes

The destination system must return a response otherwise the error_notification operation throws an error.

Example 1: Chime notification

  1. {
  2. "error_notification": {
  3. "destination": {
  4. "chime": {
  5. "url": "<url>"
  6. }
  7. },
  8. "message_template": {
  9. "source": "The index {{ctx.index}} failed during policy execution."
  10. }
  11. }
  12. }

Example 2: Custom webhook notification

  1. {
  2. "error_notification": {
  3. "destination": {
  4. "custom_webhook": {
  5. "url": "https://<your_webhook>"
  6. }
  7. },
  8. "message_template": {
  9. "source": "The index {{ctx.index}} failed during policy execution."
  10. }
  11. }
  12. }

Example 3: Slack notification

  1. {
  2. "error_notification": {
  3. "destination": {
  4. "slack": {
  5. "url": "https://hooks.slack.com/services/xxx/xxxxxx"
  6. }
  7. },
  8. "message_template": {
  9. "source": "The index {{ctx.index}} failed during policy execution."
  10. }
  11. }
  12. }

You can use the same options for ctx variables as the notification operation.

Sample policy with ISM template

The following sample template policy is for a rollover use case.

  1. Create a policy with an ism_template field:

    1. PUT _plugins/_ism/policies/rollover_policy
    2. {
    3. "policy": {
    4. "description": "Example rollover policy.",
    5. "default_state": "rollover",
    6. "states": [
    7. {
    8. "name": "rollover",
    9. "actions": [
    10. {
    11. "rollover": {
    12. "min_doc_count": 1
    13. }
    14. }
    15. ],
    16. "transitions": []
    17. }
    18. ],
    19. "ism_template": {
    20. "index_patterns": ["log*"],
    21. "priority": 100
    22. }
    23. }
    24. }

    You need to specify the index_patterns field. If you don’t specify a value for priority, it defaults to 0.

  2. Set up a template with the rollover_alias as log :

    1. PUT _index_template/ism_rollover
    2. {
    3. "index_patterns": ["log*"],
    4. "settings": {
    5. "plugins.index_state_management.rollover_alias": "log"
    6. }
    7. }
  3. Create an index with the log alias:

    1. PUT log-000001
    2. {
    3. "aliases": {
    4. "log": {
    5. "is_write_index": true
    6. }
    7. }
    8. }
  4. Index a document to trigger the rollover condition:

    1. POST log/_doc
    2. {
    3. "message": "dummy"
    4. }

Example policy

The following example policy implements a hot, warm, and delete workflow. You can use this policy as a template to prioritize resources to your indices based on their levels of activity.

In this case, an index is initially in a hot state. After a day, it changes to a warm state, where the number of replicas increases to 5 to improve the read performance.

After 30 days, the policy moves this index into a delete state. The service sends a notification to a Chime room that the index is being deleted, and then permanently deletes it.

  1. {
  2. "policy": {
  3. "description": "hot warm delete workflow",
  4. "default_state": "hot",
  5. "schema_version": 1,
  6. "states": [
  7. {
  8. "name": "hot",
  9. "actions": [
  10. {
  11. "rollover": {
  12. "min_index_age": "1d"
  13. }
  14. }
  15. ],
  16. "transitions": [
  17. {
  18. "state_name": "warm"
  19. }
  20. ]
  21. },
  22. {
  23. "name": "warm",
  24. "actions": [
  25. {
  26. "replica_count": {
  27. "number_of_replicas": 5
  28. }
  29. }
  30. ],
  31. "transitions": [
  32. {
  33. "state_name": "delete",
  34. "conditions": {
  35. "min_index_age": "30d"
  36. }
  37. }
  38. ]
  39. },
  40. {
  41. "name": "delete",
  42. "actions": [
  43. {
  44. "notification": {
  45. "destination": {
  46. "chime": {
  47. "url": "<URL>"
  48. }
  49. },
  50. "message_template": {
  51. "source": "The index {{ctx.index}} is being deleted"
  52. }
  53. }
  54. },
  55. {
  56. "delete": {}
  57. }
  58. ]
  59. }
  60. ]
  61. }
  62. }

This diagram shows the states, transitions, and actions of the above policy as a finite-state machine. For more information about finite-state machines, see Wikipedia.

Policy State Machine