policy-definitions.asciidoc 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747
  1. [role="xpack"]
  2. [testenv="basic"]
  3. [[ilm-policy-definition]]
  4. == Policy phases and actions
  5. There are four stages in the index lifecycle, in the order
  6. they are executed.
  7. [options="header"]
  8. |======
  9. | Name | Description
  10. | `hot` | The index is actively being written to
  11. | `warm` | The index is generally not being written to, but is still queried
  12. | `cold` | The index is no longer being updated and is seldom queried. The
  13. information still needs to be searchable, but it's okay if those queries are
  14. slower.
  15. | `delete` | The index is no longer needed and can safely be deleted
  16. |======
  17. Each of these stages is called a "phase". A policy does not need to configure
  18. each phase for an index. For example, one policy may define only the hot
  19. phase and the delete phase, while another may define all four phases.
  20. === Timing
  21. Indices enter phases based on a phase's `min_age` parameter.
  22. The index will not enter the phase until the index's age is older than that
  23. of the `min_age`. The parameter is configured using a time
  24. duration format (see <<time-units, Time Units>>).
  25. `min_age` defaults to zero seconds `0s` for each phase if not specified.
  26. [source,js]
  27. --------------------------------------------------
  28. PUT _ilm/policy/my_policy
  29. {
  30. "policy": {
  31. "phases": {
  32. "warm": {
  33. "min_age": "1d",
  34. "actions": {
  35. "allocate": {
  36. "number_of_replicas": 1
  37. }
  38. }
  39. },
  40. "delete": {
  41. "min_age": "30d",
  42. "actions": {
  43. "delete": {}
  44. }
  45. }
  46. }
  47. }
  48. }
  49. --------------------------------------------------
  50. // CONSOLE
  51. The Above example configures a policy that moves the index into the warm
  52. phase after one day. Until then, the index is in a waiting state. After
  53. moving into the warm phase, it will wait until 30 days have elapsed before
  54. moving to the delete phase and deleting the index.
  55. `min_age` is usually the time elapsed from the time the index is created. If the
  56. index is rolled over, then `min_age` is the time elapsed from the time the index
  57. is rolled over. The intention here is to execute following phases and actions
  58. relative to when data was written last to a rolled over index.
  59. The previous phase's actions must complete before {ilm} will check `min_age`
  60. and transition into the next phase.
  61. === Phase Execution
  62. The current phase definition, of an index's policy being executed, is stored
  63. in the index's metadata. The phase and its actions are compiled into a series
  64. of discrete steps that are executed sequentially. Since some {ilm-init} actions
  65. are more complex and involve multiple operations against an index, each of these
  66. operations are done in isolation in a unit called a "step". The
  67. <<ilm-explain-lifecycle,Explain Lifecycle API>> exposes this information to us
  68. to see which step our index is either to execute next, or is currently
  69. executing.
  70. === Actions
  71. The below list shows the actions which are available in each phase.
  72. * Hot
  73. - <<ilm-set-priority-action,Set Priority>>
  74. - <<ilm-rollover-action,Rollover>>
  75. - <<ilm-unfollow-action,Unfollow>>
  76. * Warm
  77. - <<ilm-set-priority-action,Set Priority>>
  78. - <<ilm-allocate-action,Allocate>>
  79. - <<ilm-readonly-action,Read-Only>>
  80. - <<ilm-forcemerge-action,Force Merge>>
  81. - <<ilm-shrink-action,Shrink>>
  82. - <<ilm-unfollow-action,Unfollow>>
  83. * Cold
  84. - <<ilm-set-priority-action,Set Priority>>
  85. - <<ilm-allocate-action,Allocate>>
  86. - <<ilm-freeze-action,Freeze>>
  87. - <<ilm-unfollow-action,Unfollow>>
  88. * Delete
  89. - <<ilm-delete-action,Delete>>
  90. [[ilm-allocate-action]]
  91. ==== Allocate
  92. Phases allowed: warm, cold.
  93. The Allocate action allows you to specify which nodes are allowed to host the
  94. shards of the index and set the number of replicas.
  95. Behind the scenes, it is modifying the index settings
  96. for shard filtering and/or replica counts. When updating the number of replicas,
  97. configuring allocation rules is optional. When configuring allocation rules,
  98. setting number of replicas is optional. Although this action can be treated as
  99. two separate index settings updates, both can be configured at once.
  100. Read more about index replicas <<getting-started-shards-and-replicas,here>>.
  101. Read more about shard allocation filtering in
  102. the <<shard-allocation-filtering,Shard allocation filtering documentation>>.
  103. [[ilm-allocate-options]]
  104. .Allocate Options
  105. [options="header"]
  106. |======
  107. | Name | Required | Default | Description
  108. | `number_of_replicas` | no | - | The number of replicas to
  109. assign to the index
  110. | `include` | no | - | assigns an index to nodes
  111. having at least _one_ of the attributes
  112. | `exclude` | no | - | assigns an index to nodes having
  113. _none_ of the attributes
  114. | `require` | no | - | assigns an index to nodes having
  115. _all_ of the attributes
  116. |======
  117. If `number_of_replicas` is not configured, then at least one of `include`,
  118. `exclude`, and `require` is required. An empty Allocate Action with no configuration
  119. is invalid.
  120. ===== Example: Change number of replicas
  121. In this example, the index's number of replicas is changed to `2`, while allocation
  122. rules are unchanged.
  123. [source,js]
  124. --------------------------------------------------
  125. PUT _ilm/policy/my_policy
  126. {
  127. "policy": {
  128. "phases": {
  129. "warm": {
  130. "actions": {
  131. "allocate" : {
  132. "number_of_replicas" : 2
  133. }
  134. }
  135. }
  136. }
  137. }
  138. }
  139. --------------------------------------------------
  140. // CONSOLE
  141. ===== Example: Assign index to node with specific "box_type" attribute
  142. This example assigns the index to nodes with `box_type` attribute of "hot" or "warm".
  143. [source,js]
  144. --------------------------------------------------
  145. PUT _ilm/policy/my_policy
  146. {
  147. "policy": {
  148. "phases": {
  149. "warm": {
  150. "actions": {
  151. "allocate" : {
  152. "include" : {
  153. "box_type": "hot,warm"
  154. }
  155. }
  156. }
  157. }
  158. }
  159. }
  160. }
  161. --------------------------------------------------
  162. // CONSOLE
  163. ===== Example: Assign index to a specific node and update replica settings
  164. This example updates the index to have one replica per shard and be allocated
  165. to nodes with a `box_type` attribute of "cold".
  166. [source,js]
  167. --------------------------------------------------
  168. PUT _ilm/policy/my_policy
  169. {
  170. "policy": {
  171. "phases": {
  172. "warm": {
  173. "actions": {
  174. "allocate" : {
  175. "number_of_replicas": 1,
  176. "require" : {
  177. "box_type": "cold"
  178. }
  179. }
  180. }
  181. }
  182. }
  183. }
  184. }
  185. --------------------------------------------------
  186. // CONSOLE
  187. [[ilm-delete-action]]
  188. ==== Delete
  189. Phases allowed: delete.
  190. The Delete Action does just that, it deletes the index.
  191. This action does not have any options associated with it.
  192. [source,js]
  193. --------------------------------------------------
  194. PUT _ilm/policy/my_policy
  195. {
  196. "policy": {
  197. "phases": {
  198. "delete": {
  199. "actions": {
  200. "delete" : { }
  201. }
  202. }
  203. }
  204. }
  205. }
  206. --------------------------------------------------
  207. // CONSOLE
  208. [[ilm-forcemerge-action]]
  209. ==== Force Merge
  210. Phases allowed: warm.
  211. NOTE: Index will be be made read-only when this action is run
  212. (see: <<dynamic-index-settings,index.blocks.write>>)
  213. The Force Merge Action <<indices-forcemerge,force merges>> the index into at
  214. most a specific number of <<indices-segments,segments>>.
  215. [[ilm-forcemerge-options]]
  216. .Force Merge Options
  217. [options="header"]
  218. |======
  219. | Name | Required | Default | Description
  220. | `max_num_segments` | yes | - | The number of
  221. segments to merge to.
  222. To fully merge the
  223. index, set it to `1`
  224. |======
  225. [source,js]
  226. --------------------------------------------------
  227. PUT _ilm/policy/my_policy
  228. {
  229. "policy": {
  230. "phases": {
  231. "warm": {
  232. "actions": {
  233. "forcemerge" : {
  234. "max_num_segments": 1
  235. }
  236. }
  237. }
  238. }
  239. }
  240. }
  241. --------------------------------------------------
  242. // CONSOLE
  243. [[ilm-freeze-action]]
  244. ==== Freeze
  245. Phases allowed: cold.
  246. This action will <<frozen-indices, freeze>> the index
  247. by calling the <<freeze-index-api, Freeze Index API>>.
  248. [source,js]
  249. --------------------------------------------------
  250. PUT _ilm/policy/my_policy
  251. {
  252. "policy": {
  253. "phases": {
  254. "cold": {
  255. "actions": {
  256. "freeze" : { }
  257. }
  258. }
  259. }
  260. }
  261. }
  262. --------------------------------------------------
  263. // CONSOLE
  264. [IMPORTANT]
  265. ================================
  266. Freezing an index will close the index and reopen it within the same API call.
  267. This causes primaries to not be allocated for a short amount of time and
  268. causes the cluster to go red until the primaries are allocated again.
  269. This limitation might be removed in the future.
  270. ================================
  271. [[ilm-readonly-action]]
  272. ==== Read-Only
  273. Phases allowed: warm.
  274. This action will set the index to be read-only
  275. (see: <<dynamic-index-settings,index.blocks.write>>)
  276. This action does not have any options associated with it.
  277. [source,js]
  278. --------------------------------------------------
  279. PUT _ilm/policy/my_policy
  280. {
  281. "policy": {
  282. "phases": {
  283. "warm": {
  284. "actions": {
  285. "readonly" : { }
  286. }
  287. }
  288. }
  289. }
  290. }
  291. --------------------------------------------------
  292. // CONSOLE
  293. [[ilm-rollover-action]]
  294. ==== Rollover
  295. Phases allowed: hot.
  296. [WARNING]
  297. index format must match pattern '^.*-\\d+$', for example (`logs-000001`).
  298. [WARNING]
  299. The managed index must set `index.lifecycle.rollover_alias` as the
  300. alias to rollover. The index must also be the write index for the alias.
  301. [IMPORTANT]
  302. If a policy using the Rollover action is used on a <<ccr-put-follow,follower
  303. index>>, policy execution will wait until the leader index rolls over (or has
  304. <<skipping-rollover, otherwise been marked as complete>>), then convert the
  305. follower index into a regular index as if <<ilm-unfollow-action,the Unfollow
  306. action>> had been used instead of rolling over.
  307. For example, if an index to be managed has an alias `my_data`. The managed
  308. index "my_index" must be the write index for the alias. For more information, read
  309. <<indices-rollover-is-write-index,Write Index Alias Behavior>>.
  310. [source,js]
  311. --------------------------------------------------
  312. PUT my_index
  313. {
  314. "settings": {
  315. "index.lifecycle.name": "my_policy",
  316. "index.lifecycle.rollover_alias": "my_data"
  317. },
  318. "aliases": {
  319. "my_data": {
  320. "is_write_index": true
  321. }
  322. }
  323. }
  324. --------------------------------------------------
  325. // CONSOLE
  326. The Rollover Action rolls an alias over to a new index when the
  327. existing index meets one of the rollover conditions.
  328. [[ilm-rollover-options]]
  329. .Rollover Options
  330. [options="header"]
  331. |======
  332. | Name | Required | Default | Description
  333. | `max_size` | no | - | max primary shard index storage size.
  334. See <<byte-units, Byte Units>>
  335. for formatting
  336. | `max_docs` | no | - | max number of documents an
  337. index is to contain before
  338. rolling over.
  339. | `max_age` | no | - | max time elapsed from index
  340. creation. See
  341. <<time-units, Time Units>>
  342. for formatting
  343. |======
  344. At least one of `max_size`, `max_docs`, `max_age` or any combinations of the
  345. three are required to be specified.
  346. ===== Example: Rollover when index is too large
  347. This example rolls the index over when it is at least 100 gigabytes.
  348. [source,js]
  349. --------------------------------------------------
  350. PUT _ilm/policy/my_policy
  351. {
  352. "policy": {
  353. "phases": {
  354. "hot": {
  355. "actions": {
  356. "rollover" : {
  357. "max_size": "100GB"
  358. }
  359. }
  360. }
  361. }
  362. }
  363. }
  364. --------------------------------------------------
  365. // CONSOLE
  366. ===== Example: Rollover when index has too many documents
  367. This example rolls the index over when it contains at least
  368. 100000000 documents.
  369. [source,js]
  370. --------------------------------------------------
  371. PUT _ilm/policy/my_policy
  372. {
  373. "policy": {
  374. "phases": {
  375. "hot": {
  376. "actions": {
  377. "rollover" : {
  378. "max_docs": 100000000
  379. }
  380. }
  381. }
  382. }
  383. }
  384. }
  385. --------------------------------------------------
  386. // CONSOLE
  387. ===== Example: Rollover when index is too old
  388. This example rolls the index over when it has been created at least
  389. 7 days ago.
  390. [source,js]
  391. --------------------------------------------------
  392. PUT _ilm/policy/my_policy
  393. {
  394. "policy": {
  395. "phases": {
  396. "hot": {
  397. "actions": {
  398. "rollover" : {
  399. "max_age": "7d"
  400. }
  401. }
  402. }
  403. }
  404. }
  405. }
  406. --------------------------------------------------
  407. // CONSOLE
  408. ===== Example: Rollover when index is too old or too large
  409. This example rolls the index over when it has been created at least
  410. 7 days ago or it is at least 100 gigabytes. In this case, the index will be
  411. rolled over when any of the conditions is met.
  412. [source,js]
  413. --------------------------------------------------
  414. PUT _ilm/policy/my_policy
  415. {
  416. "policy": {
  417. "phases": {
  418. "hot": {
  419. "actions": {
  420. "rollover" : {
  421. "max_age": "7d",
  422. "max_size": "100GB"
  423. }
  424. }
  425. }
  426. }
  427. }
  428. }
  429. --------------------------------------------------
  430. // CONSOLE
  431. ===== Example: Rollover condition stalls phase transition
  432. The Rollover action will only complete once one of its conditions is
  433. met. This means that any proceeding phases will be blocked until Rollover
  434. succeeds.
  435. [source,js]
  436. --------------------------------------------------
  437. PUT /_ilm/policy/rollover_policy
  438. {
  439. "policy": {
  440. "phases": {
  441. "hot": {
  442. "actions": {
  443. "rollover": {
  444. "max_size": "50G"
  445. }
  446. }
  447. },
  448. "delete": {
  449. "min_age": "1d",
  450. "actions": {
  451. "delete": {}
  452. }
  453. }
  454. }
  455. }
  456. }
  457. --------------------------------------------------
  458. // CONSOLE
  459. The above example illustrates a policy which attempts to delete an
  460. index one day after the index has been rolled over. It does not
  461. delete the index one day after it has been created.
  462. [[ilm-set-priority-action]]
  463. ==== Set Priority
  464. Phases allowed: hot, warm, cold.
  465. This action sets the <<recovery-prioritization, index priority>> on the index as
  466. soon as the policy enters the hot, warm, or cold phase. Indices with a higher
  467. priority will be recovered before indices with lower priorities following a node
  468. restart. Generally, indexes in the hot phase should have the highest value and
  469. indexes in the cold phase should have the lowest values. For example:
  470. 100 for the hot phase, 50 for the warm phase, and 0 for the cold phase.
  471. Indicies that don't set this value have an implicit default priority of 1.
  472. [[ilm-set-priority-options]]
  473. .Set Priority Options
  474. [options="header"]
  475. |======
  476. | Name | Required | Default | Description
  477. | `priority` | yes | - | The priority for the index. Must be 0 or greater.
  478. The value may also be set to null to remove the priority.
  479. |======
  480. [source,js]
  481. --------------------------------------------------
  482. PUT _ilm/policy/my_policy
  483. {
  484. "policy": {
  485. "phases": {
  486. "warm": {
  487. "actions": {
  488. "set_priority" : {
  489. "priority": 50
  490. }
  491. }
  492. }
  493. }
  494. }
  495. }
  496. --------------------------------------------------
  497. // CONSOLE
  498. [[ilm-shrink-action]]
  499. ==== Shrink
  500. NOTE: Index will be be made read-only when this action is run
  501. (see: <<dynamic-index-settings,index.blocks.write>>)
  502. [IMPORTANT]
  503. If a policy using the Shrink action is used on a <<ccr-put-follow,follower
  504. index>>, policy execution will wait until the leader index rolls over (or has
  505. <<skipping-rollover, otherwise been marked as complete>>), then convert the
  506. follower index into a regular index as if <<ilm-unfollow-action,the Unfollow
  507. action>> had been used before shrink is applied, as shrink cannot be safely
  508. applied to follower indices.
  509. This action shrinks an existing index into a new index with fewer primary
  510. shards. It calls the <<indices-shrink-index,Shrink API>> to shrink the index.
  511. Since allocating all the primary shards of the index to one node is a
  512. prerequisite, this action will first allocate the primary shards to a valid
  513. node. After shrinking, it will swap aliases pointing to the original index
  514. into the new shrunken index. The new index will also have a new name:
  515. "shrink-<origin-index-name>". So if the original index was called "logs",
  516. then the new index will be named "shrink-logs".
  517. [[ilm-shrink-options]]
  518. .Shrink Options
  519. [options="header"]
  520. |======
  521. | Name | Required | Default | Description
  522. | `number_of_shards` | yes | - | The number of shards
  523. to shrink to. must be
  524. a factor of the number
  525. of shards in the
  526. source index.
  527. |======
  528. [source,js]
  529. --------------------------------------------------
  530. PUT _ilm/policy/my_policy
  531. {
  532. "policy": {
  533. "phases": {
  534. "warm": {
  535. "actions": {
  536. "shrink" : {
  537. "number_of_shards": 1
  538. }
  539. }
  540. }
  541. }
  542. }
  543. }
  544. --------------------------------------------------
  545. // CONSOLE
  546. [[ilm-unfollow-action]]
  547. ==== Unfollow
  548. [IMPORTANT]
  549. This action may be used explicitly, as shown below, but this action is also run
  550. before <<ilm-rollover-action,the Rollover action>> and <<ilm-shrink-action,the
  551. Shrink action>> as described in the documentation for those actions.
  552. This action turns a {ref}/ccr-apis.html[ccr] follower index
  553. into a regular index. This can be desired when moving follower
  554. indices into the next phase. Also certain actions like shrink
  555. and rollover can then be performed safely on follower indices.
  556. This action will wait until is it safe to convert a follower index into a
  557. regular index. In particular, the following conditions must be met:
  558. * The leader index must have `index.lifecycle.indexing_complete` set to `true`.
  559. This happens automatically if the leader index is rolled over using
  560. <<ilm-rollover-action,the Rollover action>>, or may be set manually using
  561. the <<indices-update-settings,Index Settings API>>.
  562. * All operations performed on the leader index must have been replicated to the
  563. follower index. This ensures that no operations will be lost when the index is
  564. converted into a regular index.
  565. If the unfollow action encounters a follower index then
  566. the following operations will be performed on it:
  567. * Pauses indexing following for the follower index.
  568. * Closes the follower index.
  569. * Unfollows the follower index.
  570. * Opens the follower index (which is at this point is a regular index).
  571. The unfollow action does not have any options and
  572. if it encounters a non follower index, then the
  573. unfollow action leaves that index untouched and
  574. lets the next action operate on this index.
  575. [source,js]
  576. --------------------------------------------------
  577. PUT _ilm/policy/my_policy
  578. {
  579. "policy": {
  580. "phases": {
  581. "hot": {
  582. "actions": {
  583. "unfollow" : {}
  584. }
  585. }
  586. }
  587. }
  588. }
  589. --------------------------------------------------
  590. // CONSOLE
  591. === Full Policy
  592. With all of these actions, we can support complex management strategies for our
  593. indices. This policy will define an index that will start in the hot phase,
  594. rolling over every 50 GB or 7 days. After 30 days it enters the warm phase
  595. and increases the replicas to 2, force merges and shrinks. After 60 days
  596. it enters the cold phase and allocates to "cold" nodes, and after 90 days the
  597. index is deleted.
  598. [source,js]
  599. --------------------------------------------------
  600. PUT _ilm/policy/full_policy
  601. {
  602. "policy": {
  603. "phases": {
  604. "hot": {
  605. "actions": {
  606. "rollover": {
  607. "max_age": "7d",
  608. "max_size": "50G"
  609. }
  610. }
  611. },
  612. "warm": {
  613. "min_age": "30d",
  614. "actions": {
  615. "forcemerge": {
  616. "max_num_segments": 1
  617. },
  618. "shrink": {
  619. "number_of_shards": 1
  620. },
  621. "allocate": {
  622. "number_of_replicas": 2
  623. }
  624. }
  625. },
  626. "cold": {
  627. "min_age": "60d",
  628. "actions": {
  629. "allocate": {
  630. "require": {
  631. "type": "cold"
  632. }
  633. }
  634. }
  635. },
  636. "delete": {
  637. "min_age": "90d",
  638. "actions": {
  639. "delete": {}
  640. }
  641. }
  642. }
  643. }
  644. }
  645. --------------------------------------------------
  646. // CONSOLE