policy-definitions.asciidoc 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609
  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-readonly-action]]
  242. ==== Read-Only
  243. Phases allowed: warm.
  244. This action will set the index to be read-only
  245. (see: <<dynamic-index-settings,index.blocks.write>>)
  246. This action does not have any options associated with it.
  247. [source,js]
  248. --------------------------------------------------
  249. PUT _ilm/policy/my_policy
  250. {
  251. "policy": {
  252. "phases": {
  253. "warm": {
  254. "actions": {
  255. "readonly" : { }
  256. }
  257. }
  258. }
  259. }
  260. }
  261. --------------------------------------------------
  262. // CONSOLE
  263. [[ilm-rollover-action]]
  264. ==== Rollover
  265. Phases allowed: hot.
  266. [WARNING]
  267. index format must match pattern '^.*-\\d+$', for example (`logs-000001`).
  268. [WARNING]
  269. The managed index must set `index.lifecycle.rollover_alias` as the
  270. alias to rollover. The index must also be the write index for the alias.
  271. For example, if an index to be managed has an alias `my_data`. The managed
  272. index "my_index" must be the write index for the alias. For more information, read
  273. <<indices-rollover-is-write-index,Write Index Alias Behavior>>.
  274. [source,js]
  275. --------------------------------------------------
  276. PUT my_index
  277. {
  278. "settings": {
  279. "index.lifecycle.name": "my_policy",
  280. "index.lifecycle.rollover_alias": "my_data"
  281. },
  282. "aliases": {
  283. "my_data": {
  284. "is_write_index": true
  285. }
  286. }
  287. }
  288. --------------------------------------------------
  289. // CONSOLE
  290. The Rollover Action rolls an alias over to a new index when the
  291. existing index meets one of the rollover conditions.
  292. [[ilm-rollover-options]]
  293. .Rollover Options
  294. [options="header"]
  295. |======
  296. | Name | Required | Default | Description
  297. | `max_size` | no | - | max index storage size.
  298. See <<byte-units, Byte Units>>
  299. for formatting
  300. | `max_docs` | no | - | max number of documents an
  301. index is to contain before
  302. rolling over.
  303. | `max_age` | no | - | max time elapsed from index
  304. creation. See
  305. <<time-units, Time Units>>
  306. for formatting
  307. |======
  308. At least one of `max_size`, `max_docs`, `max_age` or any combinations of the
  309. three are required to be specified.
  310. ===== Example: Rollover when index is too large
  311. This example rolls the index over when it is at least 100 gigabytes.
  312. [source,js]
  313. --------------------------------------------------
  314. PUT _ilm/policy/my_policy
  315. {
  316. "policy": {
  317. "phases": {
  318. "hot": {
  319. "actions": {
  320. "rollover" : {
  321. "max_size": "100GB"
  322. }
  323. }
  324. }
  325. }
  326. }
  327. }
  328. --------------------------------------------------
  329. // CONSOLE
  330. ===== Example: Rollover when index has too many documents
  331. This example rolls the index over when it contains at least
  332. 1000000 documents.
  333. [source,js]
  334. --------------------------------------------------
  335. PUT _ilm/policy/my_policy
  336. {
  337. "policy": {
  338. "phases": {
  339. "hot": {
  340. "actions": {
  341. "rollover" : {
  342. "max_docs": 1000000
  343. }
  344. }
  345. }
  346. }
  347. }
  348. }
  349. --------------------------------------------------
  350. // CONSOLE
  351. ===== Example: Rollover when index is too old
  352. This example rolls the index over when it has been created at least
  353. 7 days ago.
  354. [source,js]
  355. --------------------------------------------------
  356. PUT _ilm/policy/my_policy
  357. {
  358. "policy": {
  359. "phases": {
  360. "hot": {
  361. "actions": {
  362. "rollover" : {
  363. "max_age": "7d"
  364. }
  365. }
  366. }
  367. }
  368. }
  369. }
  370. --------------------------------------------------
  371. // CONSOLE
  372. ===== Example: Rollover when index is too old or too large
  373. This example rolls the index over when it has been created at least
  374. 7 days ago or it is at least 100 gigabytes. In this case, the index will be
  375. rolled over when any of the conditions is met.
  376. [source,js]
  377. --------------------------------------------------
  378. PUT _ilm/policy/my_policy
  379. {
  380. "policy": {
  381. "phases": {
  382. "hot": {
  383. "actions": {
  384. "rollover" : {
  385. "max_age": "7d",
  386. "max_size": "100GB"
  387. }
  388. }
  389. }
  390. }
  391. }
  392. }
  393. --------------------------------------------------
  394. // CONSOLE
  395. ===== Example: Rollover condition stalls phase transition
  396. The Rollover action will only complete once one of its conditions is
  397. met. This means that any proceeding phases will be blocked until Rollover
  398. succeeds.
  399. [source,js]
  400. --------------------------------------------------
  401. PUT /_ilm/policy/rollover_policy
  402. {
  403. "policy": {
  404. "phases": {
  405. "hot": {
  406. "actions": {
  407. "rollover": {
  408. "max_size": "50G"
  409. }
  410. }
  411. },
  412. "delete": {
  413. "min_age": "1d",
  414. "actions": {
  415. "delete": {}
  416. }
  417. }
  418. }
  419. }
  420. }
  421. --------------------------------------------------
  422. // CONSOLE
  423. The above example illustrates a policy which attempts to delete an
  424. index one day after the index has been rolled over. It does not
  425. delete the index one day after it has been created.
  426. [[ilm-shrink-action]]
  427. ==== Shrink
  428. NOTE: Index will be be made read-only when this action is run
  429. (see: <<dynamic-index-settings,index.blocks.write>>)
  430. This action shrinks an existing index into a new index with fewer primary
  431. shards. It calls the <<indices-shrink-index,Shrink API>> to shrink the index.
  432. Since allocating all the primary shards of the index to one node is a
  433. prerequisite, this action will first allocate the primary shards to a valid
  434. node. After shrinking, it will swap aliases pointing to the original index
  435. into the new shrunken index. The new index will also have a new name:
  436. "shrink-<origin-index-name>". So if the original index was called "logs",
  437. then the new index will be named "shrink-logs".
  438. [[ilm-shrink-options]]
  439. .Shrink Options
  440. [options="header"]
  441. |======
  442. | Name | Required | Default | Description
  443. | `number_of_shards` | yes | - | The number of shards
  444. to shrink to. must be
  445. a factor of the number
  446. of shards in the
  447. source index.
  448. |======
  449. [source,js]
  450. --------------------------------------------------
  451. PUT _ilm/policy/my_policy
  452. {
  453. "policy": {
  454. "phases": {
  455. "warm": {
  456. "actions": {
  457. "shrink" : {
  458. "number_of_shards": 1
  459. }
  460. }
  461. }
  462. }
  463. }
  464. }
  465. --------------------------------------------------
  466. // CONSOLE
  467. === Full Policy
  468. beta[]
  469. With all of these actions, we can support complex management strategies for our
  470. indices. This policy will define an index that will start in the hot phase,
  471. rolling over every 20g or 7 days. After 30 days it enters the warm phase
  472. and increases the replicas to 2, force merges and shrinks. After 60 days
  473. it enters the cold phase and allocates to "cold" nodes, and after 90 days the
  474. index is deleted.
  475. [source,js]
  476. --------------------------------------------------
  477. PUT _ilm/policy/full_policy
  478. {
  479. "policy": {
  480. "phases": {
  481. "hot": {
  482. "actions": {
  483. "rollover": {
  484. "max_age": "7d",
  485. "max_size": "20G"
  486. }
  487. }
  488. },
  489. "warm": {
  490. "min_age": "30d",
  491. "actions": {
  492. "forcemerge": {
  493. "max_num_segments": 1
  494. },
  495. "shrink": {
  496. "number_of_shards": 1
  497. },
  498. "allocate": {
  499. "number_of_replicas": 2
  500. }
  501. }
  502. },
  503. "cold": {
  504. "min_age": "60d",
  505. "actions": {
  506. "allocate": {
  507. "require": {
  508. "type": "cold"
  509. }
  510. }
  511. }
  512. },
  513. "delete": {
  514. "min_age": "90d",
  515. "actions": {
  516. "delete": {}
  517. }
  518. }
  519. }
  520. }
  521. }
  522. --------------------------------------------------
  523. // CONSOLE