123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504 |
- [role="xpack"]
- [testenv="basic"]
- [[update-lifecycle-policy]]
- == Update lifecycle policy
- ++++
- <titleabbrev>Update policy</titleabbrev>
- ++++
- You can update an existing lifecycle policy to fix mistakes or change
- strategies for newly created indices. It is possible to update policy definitions
- and an index's `index.lifecycle.name` settings independently. To prevent the situation
- that phase definitions are modified while currently being executed on an index, each index
- will keep the version of the current phase definition it began execution with until it completes.
- This also means that changes to `min_age` will not be propagated. If a new policy is set that
- introduces a later `min_age` for the currently executing phase, that new `min_age` will not
- be picked up by the update.
- There are three scenarios for examining the behavior updating policies and
- their effects on policy execution on indices.
- === Updates to policies not managing indices
- Indices not referencing an existing policy that is updated will not be affected.
- If an index is assigned to the policy, it will be assigned the latest version of that policy
- To show this, let's create a policy `my_policy`.
- [source,console]
- ------------------------
- PUT _ilm/policy/my_policy
- {
- "policy": {
- "phases": {
- "hot": {
- "actions": {
- "rollover": {
- "max_size": "25GB"
- }
- }
- },
- "delete": {
- "min_age": "30d",
- "actions": {
- "delete": {}
- }
- }
- }
- }
- }
- ------------------------
- This newly defined policy will be created and assigned to have a version equal
- to 1. Since we haven't assigned any indices to this policy, any updates that
- occur will be reflected completely on indices that are newly set to be managed
- by this policy.
- Updating the Delete phase's minimum age can be done in an update request.
- [source,console]
- ------------------------
- PUT _ilm/policy/my_policy
- {
- "policy": {
- "phases": {
- "hot": {
- "actions": {
- "rollover": {
- "max_size": "25GB"
- }
- }
- },
- "delete": {
- "min_age": "10d", <1>
- "actions": {
- "delete": {}
- }
- }
- }
- }
- }
- ------------------------
- // TEST[continued]
- <1> update `min_age` to 10 days
- //////////
- [source,console]
- --------------------------------------------------
- GET _ilm/policy/my_policy
- --------------------------------------------------
- // TEST[continued]
- //////////
- When we get the policy, we will see it reflect our latest changes, but
- with its version bumped to 2.
- [source,console-result]
- --------------------------------------------------
- {
- "my_policy": {
- "version": 2, <1>
- "modified_date": 82392349, <2>
- "policy": {
- "phases": {
- "hot": {
- "min_age": "0ms",
- "actions": {
- "rollover": {
- "max_size": "25gb"
- }
- }
- },
- "delete": {
- "min_age": "10d",
- "actions": {
- "delete": {}
- }
- }
- }
- }
- }
- }
- --------------------------------------------------
- // TESTRESPONSE[s/"modified_date": 82392349/"modified_date": $body.my_policy.modified_date/]
- <1> The updated version value
- <2> The timestamp when this policy was updated last.
- Afterwords, any indices set to `my_policy` will execute against version 2 of
- the policy.
- === Updates to executing policies
- 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.
- [source,console]
- ------------------------
- PUT _ilm/policy/my_executing_policy
- {
- "policy": {
- "phases": {
- "hot": {
- "actions": {
- "rollover": {
- "max_docs": 1
- }
- }
- },
- "delete": {
- "min_age": "10d",
- "actions": {
- "delete": {}
- }
- }
- }
- }
- }
- ------------------------
- ////
- [source,console]
- ------------------------
- PUT my_index
- {
- "settings": {
- "index.lifecycle.name": "my_executing_policy"
- }
- }
- ------------------------
- // TEST[continued]
- ////
- The <<ilm-explain-lifecycle,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.
- [source,console]
- --------------------------------------------------
- GET my_index/_ilm/explain
- --------------------------------------------------
- // TEST[continued]
- [source,console-result]
- --------------------------------------------------
- {
- "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
- }
- }
- }
- }
- }
- }
- }
- --------------------------------------------------
- // TESTRESPONSE[skip:no way to know if we will get this response immediately]
- We can update `my_executing_policy` to enter the hot phase after one day.
- [source,console]
- ------------------------
- PUT _ilm/policy/my_executing_policy
- {
- "policy": {
- "phases": {
- "hot": {
- "min_age": "1d", <1>
- "actions": {
- "rollover": {
- "max_docs": 1
- }
- }
- },
- "delete": {
- "min_age": "10d",
- "actions": {
- "delete": {}
- }
- }
- }
- }
- }
- ------------------------
- // TEST[continued]
- <1> 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.
- ////
- [source,console]
- --------------------------------------------------
- GET my_index/_ilm/explain
- --------------------------------------------------
- // TEST[continued]
- ////
- [source,console-result]
- --------------------------------------------------
- {
- "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, <1>
- "phase_definition": {
- "min_age": "0ms",
- "actions": {
- "rollover": {
- "max_docs": 1
- }
- }
- }
- }
- }
- }
- }
- --------------------------------------------------
- // TESTRESPONSE[skip:no way to know if we will get this response immediately]
- <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.
- [source,console]
- ------------------------
- PUT _ilm/policy/my_executing_policy
- {
- "policy": {
- "phases": {
- "warm": {
- "min_age": "1d",
- "actions": {
- "forcemerge": {
- "max_num_segments": 1
- }
- }
- },
- "delete": {
- "min_age": "10d",
- "actions": {
- "delete": {}
- }
- }
- }
- }
- }
- ------------------------
- // TEST[continued]
- 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.
- ////
- [source,console]
- --------------------------------------------------
- GET my_index/_ilm/explain
- --------------------------------------------------
- // TEST[continued]
- ////
- [source,console-result]
- --------------------------------------------------
- {
- "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, <1>
- "phase_definition": {
- "min_age": "0ms",
- "actions": {
- "rollover": {
- "max_docs": 1
- }
- }
- }
- }
- }
- }
- }
- --------------------------------------------------
- // TESTRESPONSE[skip:no way to know if we will get this response immediately]
- <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.
- ////
- [source,console]
- --------------------------------------------------
- PUT my_index/_doc/1
- {
- "foo": "bar"
- }
- GET my_index/_ilm/explain
- --------------------------------------------------
- // TEST[continued]
- ////
- [source,console-result]
- --------------------------------------------------
- {
- "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, <1>
- "phase_definition": {
- "min_age": "1d",
- "actions": {
- "forcemerge": {
- "max_num_segments": 1
- }
- }
- }
- }
- }
- }
- }
- --------------------------------------------------
- // TESTRESPONSE[skip:There is no way to force the index to move to the next step in a timely manner]
- <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.
- === Switching policies for an index
- Setting `index.lifecycle.name` to a different policy behaves much like a policy update, but instead of just
- switching to a different version, it switches to a different policy.
- After setting a policy for an index, we can switch out `my_policy` with
- `my_other_policy` by just updating the index's `index.lifecycle.name`
- setting to the new policy. After completing its currently executed phase,
- it will move on to the next phase in `my_other_policy`. So if it was on the
- `hot` phase before, it will move to the `delete` phase after the `hot` phase concluded.
- ////
- [source,console]
- ------------------------
- PUT _ilm/policy/my_policy
- {
- "policy": {
- "phases": {
- "hot": {
- "actions": {
- "rollover": {
- "max_size": "25GB"
- }
- }
- },
- "delete": {
- "min_age": "10d",
- "actions": {
- "delete": {}
- }
- }
- }
- }
- }
- PUT _ilm/policy/my_other_policy
- {
- "policy": {
- "phases": {
- "delete": {
- "min_age": "1d",
- "actions": {
- "delete": {}
- }
- }
- }
- }
- }
- PUT my_index
- {
- "settings": {
- "index.lifecycle.name": "my_policy"
- }
- }
- ------------------------
- ////
- [source,console]
- --------------------------------------------------
- PUT my_index/_settings
- {
- "lifecycle.name": "my_other_policy"
- }
- --------------------------------------------------
- // TEST[continued]
- The change to the new policy will not happen immediately. The currently executing phase
- of the existing policy for `my_index` will continue to execute until it completes. Once
- completed, `my_index` will move to being managed by the `my_other_policy`.
|