policy-definitions.asciidoc 17 KB

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