Updates to executing policies

edit

Indices preserve the phase definition from the latest policy version that existed at the time that it entered that phase. Changes to the currently-executing phase within policy updates will not be reflected during execution. This means that updates to the hot phase, for example, will not affect indices that are currently executing the corresponding hot phase.

Let’s say we have an index my_index managed by the below my_executing_policy definition.

PUT _ilm/policy/my_executing_policy
{
  "policy": {
    "phases": {
      "hot": {
        "actions": {
          "rollover": {
            "max_docs": 1
          }
        }
      },
      "delete": {
        "min_age": "10d",
        "actions": {
          "delete": {}
        }
      }
    }
  }
}

The Explain API is useful to introspect managed indices to see which phase definition they are currently executing. Using this API, we can find out that my_index is currently checking if it is ready to be rolled over.

GET my_index/_ilm/explain
{
  "indices": {
    "my_index": {
      "index": "my_index",
      "managed": true,
      "policy": "my_executing_policy",
      "lifecycle_date_millis": 1538475653281,
      "age": "30s",
      "phase": "hot",
      "phase_time_millis": 1538475653317,
      "action": "rollover",
      "action_time_millis": 1538475653317,
      "step": "check-rollover-ready",
      "step_time_millis": 1538475653317,
      "phase_execution": {
        "policy": "my_executing_policy",
        "modified_date_in_millis": 1538475653317,
        "version": 1,
        "phase_definition": {
          "min_age": "0ms",
          "actions": {
            "rollover": {
              "max_docs": 1
            }
          }
        }
      }
    }
  }
}

We can update my_executing_policy to enter the hot phase after one day.

PUT _ilm/policy/my_executing_policy
{
  "policy": {
    "phases": {
      "hot": {
        "min_age": "1d", 
        "actions": {
          "rollover": {
            "max_docs": 1
          }
        }
      },
      "delete": {
        "min_age": "10d",
        "actions": {
          "delete": {}
        }
      }
    }
  }
}

updated min_age from "0ms" to "1d"

The index my_index has already entered the hot phase, so it will still use version 1 of the policy until it completes the hot phase.

{
  "indices": {
    "my_index": {
      "index": "my_index",
      "managed": true,
      "policy": "my_executing_policy",
      "lifecycle_date_millis": 1538475653281,
      "age": "30s",
      "phase": "hot",
      "phase_time_millis": 1538475653317,
      "action": "rollover",
      "action_time_millis": 1538475653317,
      "step": "check-rollover-ready",
      "step_time_millis": 1538475653317,
      "phase_execution": {
        "policy": "my_executing_policy",
        "modified_date_in_millis": 1538475653317,
        "version": 1, 
        "phase_definition": {
          "min_age": "0ms",
          "actions": {
            "rollover": {
              "max_docs": 1
            }
          }
        }
      }
    }
  }
}

the version of the policy used for executing the hot phase

We can also update my_executing_policy to have no rollover action and, instead, go directly into a newly introduced warm phase.

PUT _ilm/policy/my_executing_policy
{
  "policy": {
    "phases": {
      "warm": {
        "min_age": "1d",
        "actions": {
          "forcemerge": {
            "max_num_segments": 1
          }
        }
      },
      "delete": {
        "min_age": "10d",
        "actions": {
          "delete": {}
        }
      }
    }
  }
}

Now, version 3 of this policy has no hot phase, but if we run the Explain API again, we will see that nothing has changed. The index my_index is still executing version 1 of the policy.

{
  "indices": {
    "my_index": {
      "index": "my_index",
      "managed": true,
      "policy": "my_executing_policy",
      "lifecycle_date_millis": 1538475653281,
      "age": "30s",
      "phase": "hot",
      "phase_time_millis": 1538475653317,
      "action": "rollover",
      "action_time_millis": 1538475653317,
      "step": "check-rollover-ready",
      "step_time_millis": 1538475653317,
      "phase_execution": {
        "policy": "my_executing_policy",
        "modified_date_in_millis": 1538475653317,
        "version": 1, 
        "phase_definition": {
          "min_age": "0ms",
          "actions": {
            "rollover": {
              "max_docs": 1
            }
          }
        }
      }
    }
  }
}

the version of the policy used for executing the hot phase

After indexing one document into my_index so that rollover succeeds and moves onto the next phase, we will notice something new. The index will move into the next phase in the updated version 3 of its policy.

{
  "indices": {
    "my_index": {
      "index": "my_index",
      "managed": true,
      "policy": "my_executing_policy",
      "lifecycle_date_millis": 1538475653281,
      "age": "30s",
      "phase": "warm",
      "phase_time_millis": 1538475653317,
      "action": "forcemerge",
      "action_time_millis": 1538475653317,
      "step": "forcemerge",
      "step_time_millis": 1538475653317,
      "phase_execution": {
        "policy": "my_executing_policy",
        "modified_date_in_millis": 1538475653317,
        "version": 3, 
        "phase_definition": {
          "min_age": "1d",
          "actions": {
            "forcemerge": {
              "max_num_segments": 1
            }
          }
        }
      }
    }
  }
}

The index has moved to using version 3 of the policy

my_index will move to the next phase in the latest policy definition, which is the newly added warm phase.