update-lifecycle-policy.asciidoc 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512
  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,js]
  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. // CONSOLE
  46. This newly defined policy will be created and assigned to have a version equal
  47. to 1. Since we haven't assigned any indices to this policy, any updates that
  48. occur will be reflected completely on indices that are newly set to be managed
  49. by this policy.
  50. Updating the Delete phase's minimum age can be done in an update request.
  51. [source,js]
  52. ------------------------
  53. PUT _ilm/policy/my_policy
  54. {
  55. "policy": {
  56. "phases": {
  57. "hot": {
  58. "actions": {
  59. "rollover": {
  60. "max_size": "25GB"
  61. }
  62. }
  63. },
  64. "delete": {
  65. "min_age": "10d", <1>
  66. "actions": {
  67. "delete": {}
  68. }
  69. }
  70. }
  71. }
  72. }
  73. ------------------------
  74. // CONSOLE
  75. // TEST[continued]
  76. <1> update `min_age` to 10 days
  77. //////////
  78. [source,js]
  79. --------------------------------------------------
  80. GET _ilm/policy/my_policy
  81. --------------------------------------------------
  82. // CONSOLE
  83. // TEST[continued]
  84. //////////
  85. When we get the policy, we will see it reflect our latest changes, but
  86. with its version bumped to 2.
  87. [source,js]
  88. --------------------------------------------------
  89. {
  90. "my_policy": {
  91. "version": 2, <1>
  92. "modified_date": 82392349, <2>
  93. "policy": {
  94. "phases": {
  95. "hot": {
  96. "min_age": "0ms",
  97. "actions": {
  98. "rollover": {
  99. "max_size": "25gb"
  100. }
  101. }
  102. },
  103. "delete": {
  104. "min_age": "10d",
  105. "actions": {
  106. "delete": {}
  107. }
  108. }
  109. }
  110. }
  111. }
  112. }
  113. --------------------------------------------------
  114. // CONSOLE
  115. // TESTRESPONSE[s/"modified_date": 82392349/"modified_date": $body.my_policy.modified_date/]
  116. <1> The updated version value
  117. <2> The timestamp when this policy was updated last.
  118. Afterwords, any indices set to `my_policy` will execute against version 2 of
  119. the policy.
  120. === Updates to executing policies
  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. We can update `my_executing_policy` to enter the hot phase after one day.
  206. [source,js]
  207. ------------------------
  208. PUT _ilm/policy/my_executing_policy
  209. {
  210. "policy": {
  211. "phases": {
  212. "hot": {
  213. "min_age": "1d", <1>
  214. "actions": {
  215. "rollover": {
  216. "max_docs": 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. <1> updated `min_age` from "0ms" to "1d"
  233. The index `my_index` has already entered the hot phase, so it will still
  234. use version 1 of the policy until it completes the hot phase.
  235. ////
  236. [source,js]
  237. --------------------------------------------------
  238. GET my_index/_ilm/explain
  239. --------------------------------------------------
  240. // CONSOLE
  241. // TEST[continued]
  242. ////
  243. [source,js]
  244. --------------------------------------------------
  245. {
  246. "indices": {
  247. "my_index": {
  248. "index": "my_index",
  249. "managed": true,
  250. "policy": "my_executing_policy",
  251. "lifecycle_date_millis": 1538475653281,
  252. "phase": "hot",
  253. "phase_time_millis": 1538475653317,
  254. "action": "rollover",
  255. "action_time_millis": 1538475653317,
  256. "step": "check-rollover-ready",
  257. "step_time_millis": 1538475653317,
  258. "phase_execution": {
  259. "policy": "my_executing_policy",
  260. "modified_date_in_millis": 1538475653317,
  261. "version": 1, <1>
  262. "phase_definition": {
  263. "min_age": "0ms",
  264. "actions": {
  265. "rollover": {
  266. "max_docs": 1
  267. }
  268. }
  269. }
  270. }
  271. }
  272. }
  273. }
  274. --------------------------------------------------
  275. // CONSOLE
  276. // TESTRESPONSE[skip:no way to know if we will get this response immediately]
  277. <1> the version of the policy used for executing the hot phase
  278. We can also update `my_executing_policy` to have no rollover action and,
  279. instead, go directly into a newly introduced `warm` phase.
  280. [source,js]
  281. ------------------------
  282. PUT _ilm/policy/my_executing_policy
  283. {
  284. "policy": {
  285. "phases": {
  286. "warm": {
  287. "min_age": "1d",
  288. "actions": {
  289. "forcemerge": {
  290. "max_num_segments": 1
  291. }
  292. }
  293. },
  294. "delete": {
  295. "min_age": "10d",
  296. "actions": {
  297. "delete": {}
  298. }
  299. }
  300. }
  301. }
  302. }
  303. ------------------------
  304. // CONSOLE
  305. // TEST[continued]
  306. Now, version 3 of this policy has no `hot` phase, but if we run the
  307. Explain API again, we will see that nothing has changed. The index
  308. `my_index` is still executing version 1 of the policy.
  309. ////
  310. [source,js]
  311. --------------------------------------------------
  312. GET my_index/_ilm/explain
  313. --------------------------------------------------
  314. // CONSOLE
  315. // TEST[continued]
  316. ////
  317. [source,js]
  318. --------------------------------------------------
  319. {
  320. "indices": {
  321. "my_index": {
  322. "index": "my_index",
  323. "managed": true,
  324. "policy": "my_executing_policy",
  325. "lifecycle_date_millis": 1538475653281,
  326. "phase": "hot",
  327. "phase_time_millis": 1538475653317,
  328. "action": "rollover",
  329. "action_time_millis": 1538475653317,
  330. "step": "check-rollover-ready",
  331. "step_time_millis": 1538475653317,
  332. "phase_execution": {
  333. "policy": "my_executing_policy",
  334. "modified_date_in_millis": 1538475653317,
  335. "version": 1, <1>
  336. "phase_definition": {
  337. "min_age": "0ms",
  338. "actions": {
  339. "rollover": {
  340. "max_docs": 1
  341. }
  342. }
  343. }
  344. }
  345. }
  346. }
  347. }
  348. --------------------------------------------------
  349. // CONSOLE
  350. // TESTRESPONSE[skip:no way to know if we will get this response immediately]
  351. <1> the version of the policy used for executing the hot phase
  352. After indexing one document into `my_index` so that rollover succeeds and
  353. moves onto the next phase, we will notice something new. The index will
  354. move into the next phase in the updated version 3 of its policy.
  355. ////
  356. [source,js]
  357. --------------------------------------------------
  358. PUT my_index/_doc/1
  359. {
  360. "foo": "bar"
  361. }
  362. GET my_index/_ilm/explain
  363. --------------------------------------------------
  364. // CONSOLE
  365. // TEST[continued]
  366. ////
  367. [source,js]
  368. --------------------------------------------------
  369. {
  370. "indices": {
  371. "my_index": {
  372. "index": "my_index",
  373. "managed": true,
  374. "policy": "my_executing_policy",
  375. "lifecycle_date_millis": 1538475653281,
  376. "phase": "warm",
  377. "phase_time_millis": 1538475653317,
  378. "action": "forcemerge",
  379. "action_time_millis": 1538475653317,
  380. "step": "forcemerge",
  381. "step_time_millis": 1538475653317,
  382. "phase_execution": {
  383. "policy": "my_executing_policy",
  384. "modified_date_in_millis": 1538475653317,
  385. "version": 3, <1>
  386. "phase_definition": {
  387. "min_age": "1d",
  388. "actions": {
  389. "forcemerge": {
  390. "max_num_segments": 1
  391. }
  392. }
  393. }
  394. }
  395. }
  396. }
  397. }
  398. --------------------------------------------------
  399. // CONSOLE
  400. // TESTRESPONSE[skip:There is no way to force the index to move to the next step in a timely manner]
  401. <1> The index has moved to using version 3 of the policy
  402. `my_index` will move to the next phase in the latest policy definition, which is the newly added `warm` phase.
  403. === Switching policies for an index
  404. Setting `index.lifecycle.name` to a different policy behaves much like a policy update, but instead of just
  405. switching to a different version, it switches to a different policy.
  406. After setting a policy for an index, we can switch out `my_policy` with
  407. `my_other_policy` by just updating the index's `index.lifecycle.name`
  408. setting to the new policy. After completing its currently executed phase,
  409. it will move on to the next phase in `my_other_policy`. So if it was on the
  410. `hot` phase before, it will move to the `delete` phase after the `hot` phase concluded.
  411. ////
  412. [source,js]
  413. ------------------------
  414. PUT _ilm/policy/my_policy
  415. {
  416. "policy": {
  417. "phases": {
  418. "hot": {
  419. "actions": {
  420. "rollover": {
  421. "max_size": "25GB"
  422. }
  423. }
  424. },
  425. "delete": {
  426. "min_age": "10d",
  427. "actions": {
  428. "delete": {}
  429. }
  430. }
  431. }
  432. }
  433. }
  434. PUT _ilm/policy/my_other_policy
  435. {
  436. "policy": {
  437. "phases": {
  438. "delete": {
  439. "min_age": "1d",
  440. "actions": {
  441. "delete": {}
  442. }
  443. }
  444. }
  445. }
  446. }
  447. PUT my_index
  448. {
  449. "settings": {
  450. "index.lifecycle.name": "my_policy"
  451. }
  452. }
  453. ------------------------
  454. // CONSOLE
  455. ////
  456. [source,js]
  457. --------------------------------------------------
  458. PUT my_index/_settings
  459. {
  460. "lifecycle.name": "my_other_policy"
  461. }
  462. --------------------------------------------------
  463. // CONSOLE
  464. // TEST[continued]
  465. The change to the new policy will not happen immediately. The currently executing phase
  466. of the existing policy for `my_index` will continue to execute until it completes. Once
  467. completed, `my_index` will move to being managed by the `my_other_policy`.