update-lifecycle-policy.asciidoc 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432
  1. [role="xpack"]
  2. [testenv="basic"]
  3. [[update-lifecycle-policy]]
  4. == Update lifecycle policy
  5. Updating existing ILM policies is useful to fix mistakes or change
  6. strategies for newly created indices. It is possible to update policy definitions
  7. and an index's `index.lifecycle.name` settings independently. To prevent the situation
  8. that phase definitions are modified while currently being executed on an index, each index
  9. will keep the version of the current phase definition it began execution with until it completes.
  10. There are three scenarios for examining the behavior updating policies and
  11. their effects on policy execution on indices.
  12. === Updates to policies not managing indices
  13. Indices not referencing an existing policy that is updated will not be affected.
  14. If an index is assigned to the policy, it will be assigned the latest version of that policy
  15. To show this, let's create a policy `my_policy`.
  16. [source,js]
  17. ------------------------
  18. PUT _ilm/policy/my_policy
  19. {
  20. "policy": {
  21. "phases": {
  22. "hot": {
  23. "actions": {
  24. "rollover": {
  25. "max_size": "25GB"
  26. }
  27. }
  28. },
  29. "delete": {
  30. "min_age": "30d",
  31. "actions": {
  32. "delete": {}
  33. }
  34. }
  35. }
  36. }
  37. }
  38. ------------------------
  39. // CONSOLE
  40. This newly defined policy will be created and assigned to have a version equal
  41. to 1. Since we haven't assigned any indices to this policy, any updates that
  42. occur will be reflected completely on indices that are newly set to be managed
  43. by this policy.
  44. Updating the Delete phase's minimum age can be done in an update request.
  45. [source,js]
  46. ------------------------
  47. PUT _ilm/policy/my_policy
  48. {
  49. "policy": {
  50. "phases": {
  51. "hot": {
  52. "actions": {
  53. "rollover": {
  54. "max_size": "25GB"
  55. }
  56. }
  57. },
  58. "delete": {
  59. "min_age": "10d", <1>
  60. "actions": {
  61. "delete": {}
  62. }
  63. }
  64. }
  65. }
  66. }
  67. ------------------------
  68. // CONSOLE
  69. // TEST[continued]
  70. <1> update `min_age` to 10 days
  71. //////////
  72. [source,js]
  73. --------------------------------------------------
  74. GET _ilm/policy
  75. --------------------------------------------------
  76. // CONSOLE
  77. // TEST[continued]
  78. //////////
  79. When we get the policy, we will see it reflect our latest changes, but
  80. with its version bumped to 2.
  81. [source,js]
  82. --------------------------------------------------
  83. {
  84. "my_policy": {
  85. "version": 2, <1>
  86. "modified_date": 82392349, <2>
  87. "policy": {
  88. "phases": {
  89. "hot": {
  90. "min_age": "0ms",
  91. "actions": {
  92. "rollover": {
  93. "max_size": "25gb"
  94. }
  95. }
  96. },
  97. "delete": {
  98. "min_age": "10d",
  99. "actions": {
  100. "delete": {}
  101. }
  102. }
  103. }
  104. }
  105. }
  106. }
  107. --------------------------------------------------
  108. // CONSOLE
  109. // TESTRESPONSE[s/"modified_date": 82392349/"modified_date": $body.my_policy.modified_date/]
  110. <1> The updated version value
  111. <2> The timestamp when this policy was updated last.
  112. Afterwords, any indices set to `my_policy` will execute against version 2 of
  113. the policy.
  114. === Updates to executing policies
  115. Indices preserve the phase definition from the latest policy version that existed
  116. at the time that it entered that phase. Changes to the currently-executing phase within policy updates will
  117. not be reflected during execution. This means that updates to the `hot` phase, for example, will not affect
  118. indices that are currently executing the corresponding `hot` phase.
  119. Let's say we have an index `my_index` managed by the below `my_executing_policy` definition.
  120. [source,js]
  121. ------------------------
  122. PUT _ilm/policy/my_executing_policy
  123. {
  124. "policy": {
  125. "phases": {
  126. "hot": {
  127. "actions": {
  128. "rollover": {
  129. "max_docs": 1
  130. }
  131. }
  132. },
  133. "delete": {
  134. "min_age": "10d",
  135. "actions": {
  136. "delete": {}
  137. }
  138. }
  139. }
  140. }
  141. }
  142. ------------------------
  143. // CONSOLE
  144. ////
  145. [source,js]
  146. ------------------------
  147. PUT my_index
  148. {
  149. "settings": {
  150. "index.lifecycle.name": "my_executing_policy"
  151. }
  152. }
  153. ------------------------
  154. // CONSOLE
  155. // TEST[continued]
  156. ////
  157. The <<ilm-explain,Explain API>> is useful to introspect managed indices to see which phase definition they are currently executing.
  158. Using this API, we can find out that `my_index` is currently attempting to be rolled over.
  159. [source,js]
  160. --------------------------------------------------
  161. GET my_index/_ilm/explain
  162. --------------------------------------------------
  163. // CONSOLE
  164. // TEST[continued]
  165. [source,js]
  166. --------------------------------------------------
  167. {
  168. "indices": {
  169. "my_index": {
  170. "index": "my_index",
  171. "managed": true,
  172. "policy": "my_executing_policy",
  173. "lifecycle_date": 1538475653281,
  174. "phase": "hot",
  175. "phase_time": 1538475653317,
  176. "action": "rollover",
  177. "action_time": 1538475653317,
  178. "step": "attempt_rollover",
  179. "step_time": 1538475653317,
  180. "phase_execution": {
  181. "policy": "my_executing_policy",
  182. "modified_date_in_millis": 1538475653317,
  183. "version": 1,
  184. "phase_definition": {
  185. "min_age": "0ms",
  186. "actions": {
  187. "rollover": {
  188. "max_docs": 1
  189. }
  190. }
  191. }
  192. }
  193. }
  194. }
  195. }
  196. --------------------------------------------------
  197. // CONSOLE
  198. // TESTRESPONSE[s/"lifecycle_date": 1538475653281/"lifecycle_date": $body.indices.my_index.lifecycle_date/]
  199. // TESTRESPONSE[s/"phase_time": 1538475653317/"phase_time": $body.indices.my_index.phase_time/]
  200. // TESTRESPONSE[s/"action_time": 1538475653317/"action_time": $body.indices.my_index.action_time/]
  201. // TESTRESPONSE[s/"step_time": 1538475653317/"step_time": $body.indices.my_index.step_time/]
  202. // TESTRESPONSE[s/"modified_date_in_millis": 1538475653317/"modified_date_in_millis": $body.indices.my_index.phase_execution.modified_date_in_millis/]
  203. Updating `my_executing_policy` to have no rollover action and, instead, go directly into a newly introduced `warm` phase.
  204. [source,js]
  205. ------------------------
  206. PUT _ilm/policy/my_executing_policy
  207. {
  208. "policy": {
  209. "phases": {
  210. "warm": {
  211. "min_age": "1d",
  212. "actions": {
  213. "forcemerge": {
  214. "max_num_segments": 1
  215. }
  216. }
  217. },
  218. "delete": {
  219. "min_age": "10d",
  220. "actions": {
  221. "delete": {}
  222. }
  223. }
  224. }
  225. }
  226. }
  227. ------------------------
  228. // CONSOLE
  229. // TEST[continued]
  230. Now, version 2 of this policy has no `hot` phase, but if we run the Explain API again, we will see that nothing has changed.
  231. The index `my_index` is still executing version 1 of the policy.
  232. ////
  233. [source,js]
  234. --------------------------------------------------
  235. GET my_index/_ilm/explain
  236. --------------------------------------------------
  237. // CONSOLE
  238. // TEST[continued]
  239. ////
  240. [source,js]
  241. --------------------------------------------------
  242. {
  243. "indices": {
  244. "my_index": {
  245. "index": "my_index",
  246. "managed": true,
  247. "policy": "my_executing_policy",
  248. "lifecycle_date": 1538475653281,
  249. "phase": "hot",
  250. "phase_time": 1538475653317,
  251. "action": "rollover",
  252. "action_time": 1538475653317,
  253. "step": "attempt_rollover",
  254. "step_time": 1538475653317,
  255. "phase_execution": {
  256. "policy": "my_executing_policy",
  257. "modified_date_in_millis": 1538475653317,
  258. "version": 1,
  259. "phase_definition": {
  260. "min_age": "0ms",
  261. "actions": {
  262. "rollover": {
  263. "max_docs": 1
  264. }
  265. }
  266. }
  267. }
  268. }
  269. }
  270. }
  271. --------------------------------------------------
  272. // CONSOLE
  273. // TESTRESPONSE[s/"lifecycle_date": 1538475653281/"lifecycle_date": $body.indices.my_index.lifecycle_date/]
  274. // TESTRESPONSE[s/"phase_time": 1538475653317/"phase_time": $body.indices.my_index.phase_time/]
  275. // TESTRESPONSE[s/"action_time": 1538475653317/"action_time": $body.indices.my_index.action_time/]
  276. // TESTRESPONSE[s/"step_time": 1538475653317/"step_time": $body.indices.my_index.step_time/]
  277. // TESTRESPONSE[s/"modified_date_in_millis": 1538475653317/"modified_date_in_millis": $body.indices.my_index.phase_execution.modified_date_in_millis/]
  278. After indexing one document into `my_index` so that rollover succeeds and moves onto the next phase, we will notice something new. The
  279. index will move into the next phase in the updated version 2 of its policy.
  280. ////
  281. [source,js]
  282. --------------------------------------------------
  283. PUT my_index/_doc/1
  284. {
  285. "foo": "bar"
  286. }
  287. GET my_index/_ilm/explain
  288. --------------------------------------------------
  289. // CONSOLE
  290. // TEST[continued]
  291. ////
  292. [source,js]
  293. --------------------------------------------------
  294. {
  295. "indices": {
  296. "my_index": {
  297. "index": "my_index",
  298. "managed": true,
  299. "policy": "my_executing_policy",
  300. "lifecycle_date": 1538475653281,
  301. "phase": "warm",
  302. "phase_time": 1538475653317,
  303. "action": "forcemerge",
  304. "action_time": 1538475653317,
  305. "step": "forcemerge",
  306. "step_time": 1538475653317,
  307. "phase_execution": {
  308. "policy": "my_executing_policy",
  309. "modified_date_in_millis": 1538475653317,
  310. "version": 2, <1>
  311. "phase_definition": {
  312. "min_age": "1d",
  313. "actions": {
  314. "forcemerge": {
  315. "max_num_segments": 1
  316. }
  317. }
  318. }
  319. }
  320. }
  321. }
  322. }
  323. --------------------------------------------------
  324. // CONSOLE
  325. // TESTRESPONSE[skip:There is no way to force the index to move to the next step in a timely manner]
  326. <1> The index has moved to using version 2 of the policy
  327. `my_index` will move to the next phase in the latest policy definition, which is the newly added `warm` phase.
  328. === Switching policies for an index
  329. Setting `index.lifecycle.name` to a different policy behaves much like a policy update, but instead of just
  330. switching to a different version, it switches to a different policy.
  331. After setting a policy for an index, we can switch out `my_policy` with
  332. `my_other_policy` by just updating the index's `index.lifecycle.name`
  333. setting to the new policy. After completing its currently executed phase,
  334. it will move on to the next phase in `my_other_policy`. So if it was on the
  335. `hot` phase before, it will move to the `delete` phase after the `hot` phase concluded.
  336. ////
  337. [source,js]
  338. ------------------------
  339. PUT _ilm/policy/my_policy
  340. {
  341. "policy": {
  342. "phases": {
  343. "hot": {
  344. "actions": {
  345. "rollover": {
  346. "max_size": "25GB"
  347. }
  348. }
  349. },
  350. "delete": {
  351. "min_age": "10d",
  352. "actions": {
  353. "delete": {}
  354. }
  355. }
  356. }
  357. }
  358. }
  359. PUT _ilm/policy/my_other_policy
  360. {
  361. "policy": {
  362. "phases": {
  363. "delete": {
  364. "min_age": "1d",
  365. "actions": {
  366. "delete": {}
  367. }
  368. }
  369. }
  370. }
  371. }
  372. PUT my_index
  373. {
  374. "settings": {
  375. "index.lifecycle.name": "my_policy"
  376. }
  377. }
  378. ------------------------
  379. // CONSOLE
  380. ////
  381. [source,js]
  382. --------------------------------------------------
  383. PUT my_index/_settings
  384. {
  385. "lifecycle.name": "my_other_policy"
  386. }
  387. --------------------------------------------------
  388. // CONSOLE
  389. // TEST[continued]
  390. The change to the new policy will not happen immediately. The currently executing phase
  391. of the existing policy for `my_index` will continue to execute until it completes. Once
  392. completed, `my_index` will move to being managed by the `my_other_policy`.