Rollover

Phases allowed: hot.

Rolls over a target to a new index when the existing index meets one of the rollover conditions.

If the rollover action is used on a follower index, policy execution waits until the leader index rolls over (or is otherwise marked complete), then converts the follower index into a regular index with the Unfollow action.

A rollover target can be a data stream or an index alias. When targeting a data stream, the new index becomes the data stream’s write index and its generation is incremented.

To roll over an index alias, the alias and its write index must meet the following conditions:

  • The index name must match the pattern ^.\-\d+$*, for example (my-index-000001).
  • The index.lifecycle.rollover_alias must be configured as the alias to roll over.
  • The index must be the write index for the alias.

For example, if my-index-000001 has the alias my_data, the following settings must be configured.

  1. PUT my-index-000001
  2. {
  3. "settings": {
  4. "index.lifecycle.name": "my_policy",
  5. "index.lifecycle.rollover_alias": "my_data"
  6. },
  7. "aliases": {
  8. "my_data": {
  9. "is_write_index": true
  10. }
  11. }
  12. }

Options

You must specify at least one rollover condition. An empty rollover action is invalid.

max_age

(Optional, time units) Triggers roll over after the maximum elapsed time from index creation is reached.

max_docs

(Optional, integer) Triggers roll over after the specified maximum number of documents is reached. Documents added since the last refresh are not included in the document count. The document count does not include documents in replica shards.

max_size

(Optional, byte units) Triggers roll over when the index reaches a certain size. This is the total size of all primary shards in the index. Replicas are not counted toward the maximum index size.

To see the current index size, use the _cat indices API. The pri.store.size value shows the combined size of all primary shards.

Example

Roll over based on index size

This example rolls the index over when it is at least 100 gigabytes.

  1. PUT _ilm/policy/my_policy
  2. {
  3. "policy": {
  4. "phases": {
  5. "hot": {
  6. "actions": {
  7. "rollover" : {
  8. "max_size": "100GB"
  9. }
  10. }
  11. }
  12. }
  13. }
  14. }

Roll over based on document count

This example rolls the index over when it contains at least one hundred million documents.

  1. PUT _ilm/policy/my_policy
  2. {
  3. "policy": {
  4. "phases": {
  5. "hot": {
  6. "actions": {
  7. "rollover" : {
  8. "max_docs": 100000000
  9. }
  10. }
  11. }
  12. }
  13. }
  14. }

Roll over based on index age

This example rolls the index over if it was created at least 7 days ago.

  1. PUT _ilm/policy/my_policy
  2. {
  3. "policy": {
  4. "phases": {
  5. "hot": {
  6. "actions": {
  7. "rollover" : {
  8. "max_age": "7d"
  9. }
  10. }
  11. }
  12. }
  13. }
  14. }

Roll over using multiple conditions

When you specify multiple rollover conditions, the index is rolled over when any of the conditions are met. This example rolls the index over if it is at least 7 days old or at least 100 gigabytes.

  1. PUT _ilm/policy/my_policy
  2. {
  3. "policy": {
  4. "phases": {
  5. "hot": {
  6. "actions": {
  7. "rollover" : {
  8. "max_age": "7d",
  9. "max_size": "100GB"
  10. }
  11. }
  12. }
  13. }
  14. }
  15. }

Rollover condition blocks phase transition

The rollover action only completes if one of its conditions is met. This means that any subsequent phases are blocked until rollover succeeds.

For example, the following policy deletes the index one day after it rolls over. It does not delete the index one day after it was created.

  1. PUT /_ilm/policy/rollover_policy
  2. {
  3. "policy": {
  4. "phases": {
  5. "hot": {
  6. "actions": {
  7. "rollover": {
  8. "max_size": "50G"
  9. }
  10. }
  11. },
  12. "delete": {
  13. "min_age": "1d",
  14. "actions": {
  15. "delete": {}
  16. }
  17. }
  18. }
  19. }
  20. }