policy-definitions.asciidoc 21 KB

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