update-lifecycle-policy.asciidoc 11 KB

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