update-lifecycle-policy.asciidoc 13 KB

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