policy-definitions.asciidoc 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558
  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. === Actions
  63. beta[]
  64. The below list shows the actions which are available in each phase.
  65. * Hot
  66. - <<ilm-rollover-action,Rollover>>
  67. * Warm
  68. - <<ilm-allocate-action,Allocate>>
  69. - <<ilm-readonly-action,Read-Only>>
  70. - <<ilm-forcemerge-action,Force Merge>>
  71. - <<ilm-shrink-action,Shrink>>
  72. * Cold
  73. - <<ilm-allocate-action,Allocate>>
  74. * Delete
  75. - <<ilm-delete-action,Delete>>
  76. [[ilm-allocate-action]]
  77. ==== Allocate
  78. Phases allowed: warm, cold.
  79. The Allocate action allows you to specify which nodes are allowed to host the
  80. shards of the index and set the number of replicas.
  81. Behind the scenes, it is modifying the index settings
  82. for shard filtering and/or replica counts. When updating the number of replicas,
  83. configuring allocation rules is optional. When configuring allocation rules,
  84. setting number of replicas is optional. Although this action can be treated as
  85. two separate index settings updates, both can be configured at once.
  86. Read more about index replicas <<getting-started-shards-and-replicas,here>>.
  87. Read more about shard allocation filtering in
  88. the <<shard-allocation-filtering,Shard allocation filtering documentation>>.
  89. [[ilm-allocate-options]]
  90. .Allocate Options
  91. [options="header"]
  92. |======
  93. | Name | Required | Default | Description
  94. | `number_of_replicas` | no | - | The number of replicas to
  95. assign to the index
  96. | `include` | no | - | assigns an index to nodes
  97. having at least _one_ of the attributes
  98. | `exclude` | no | - | assigns an index to nodes having
  99. _none_ of the attributes
  100. | `require` | no | - | assigns an index to nodes having
  101. _all_ of the attributes
  102. |======
  103. If `number_of_replicas` is not configured, then at least one of `include`,
  104. `exclude`, and `require` is required. An empty Allocate Action with no configuration
  105. is invalid.
  106. ===== Example: Change number of replicas
  107. In this example, the index's number of replicas is changed to `2`, while allocation
  108. rules are unchanged.
  109. [source,js]
  110. --------------------------------------------------
  111. PUT _ilm/policy/my_policy
  112. {
  113. "policy": {
  114. "phases": {
  115. "warm": {
  116. "actions": {
  117. "allocate" : {
  118. "number_of_replicas" : 2
  119. }
  120. }
  121. }
  122. }
  123. }
  124. }
  125. --------------------------------------------------
  126. // CONSOLE
  127. ===== Example: Assign index to node with specific "box_type" attribute
  128. This example assigns the index to nodes with `box_type` attribute of "hot" or "warm".
  129. [source,js]
  130. --------------------------------------------------
  131. PUT _ilm/policy/my_policy
  132. {
  133. "policy": {
  134. "phases": {
  135. "warm": {
  136. "actions": {
  137. "allocate" : {
  138. "include" : {
  139. "box_type": "hot,warm"
  140. }
  141. }
  142. }
  143. }
  144. }
  145. }
  146. }
  147. --------------------------------------------------
  148. // CONSOLE
  149. ===== Example: Assign index to a specific node and update replica settings
  150. This example updates the index to have one replica per shard and be allocated
  151. to nodes with a `box_type` attribute of "cold".
  152. [source,js]
  153. --------------------------------------------------
  154. PUT _ilm/policy/my_policy
  155. {
  156. "policy": {
  157. "phases": {
  158. "warm": {
  159. "actions": {
  160. "allocate" : {
  161. "number_of_replicas": 1,
  162. "require" : {
  163. "box_type": "cold"
  164. }
  165. }
  166. }
  167. }
  168. }
  169. }
  170. }
  171. --------------------------------------------------
  172. // CONSOLE
  173. [[ilm-delete-action]]
  174. ==== Delete
  175. Phases allowed: delete.
  176. The Delete Action does just that, it deletes the index.
  177. This action does not have any options associated with it.
  178. [source,js]
  179. --------------------------------------------------
  180. PUT _ilm/policy/my_policy
  181. {
  182. "policy": {
  183. "phases": {
  184. "delete": {
  185. "actions": {
  186. "delete" : { }
  187. }
  188. }
  189. }
  190. }
  191. }
  192. --------------------------------------------------
  193. // CONSOLE
  194. [[ilm-forcemerge-action]]
  195. ==== Force Merge
  196. Phases allowed: warm.
  197. NOTE: Index will be be made read-only when this action is run
  198. (see: <<dynamic-index-settings,index.blocks.write>>)
  199. The Force Merge Action <<indices-forcemerge,force merges>> the index into at
  200. most a specific number of <<indices-segments,segments>>.
  201. [[ilm-forcemerge-options]]
  202. .Force Merge Options
  203. [options="header"]
  204. |======
  205. | Name | Required | Default | Description
  206. | `max_num_segments` | yes | - | The number of
  207. segments to merge to.
  208. To fully merge the
  209. index, set it to `1`
  210. |======
  211. [source,js]
  212. --------------------------------------------------
  213. PUT _ilm/policy/my_policy
  214. {
  215. "policy": {
  216. "phases": {
  217. "warm": {
  218. "actions": {
  219. "forcemerge" : {
  220. "max_num_segments": 1
  221. }
  222. }
  223. }
  224. }
  225. }
  226. }
  227. --------------------------------------------------
  228. // CONSOLE
  229. [[ilm-readonly-action]]
  230. ==== Read-Only
  231. Phases allowed: warm.
  232. This action will set the index to be read-only
  233. (see: <<dynamic-index-settings,index.blocks.write>>)
  234. This action does not have any options associated with it.
  235. [source,js]
  236. --------------------------------------------------
  237. PUT _ilm/policy/my_policy
  238. {
  239. "policy": {
  240. "phases": {
  241. "warm": {
  242. "actions": {
  243. "readonly" : { }
  244. }
  245. }
  246. }
  247. }
  248. }
  249. --------------------------------------------------
  250. // CONSOLE
  251. [[ilm-rollover-action]]
  252. ==== Rollover
  253. Phases allowed: hot.
  254. [WARNING]
  255. index format must match pattern '^.*-\\d+$', for example (`logs-000001`).
  256. [WARNING]
  257. The managed index must set `index.lifecycle.rollover_alias` as the
  258. alias to rollover. The index must also be the write index for the alias.
  259. For example, if an index to be managed has an alias `my_data`. The managed
  260. index "my_index" must be the write index for the alias. For more information, read
  261. <<indices-rollover-is-write-index,Write Index Alias Behavior>>.
  262. [source,js]
  263. --------------------------------------------------
  264. PUT my_index
  265. {
  266. "settings": {
  267. "index.lifecycle.name": "my_policy",
  268. "index.lifecycle.rollover_alias": "my_data"
  269. },
  270. "aliases": {
  271. "my_data": {
  272. "is_write_index": true
  273. }
  274. }
  275. }
  276. --------------------------------------------------
  277. // CONSOLE
  278. The Rollover Action rolls an alias over to a new index when the
  279. existing index meets one of the rollover conditions.
  280. [[ilm-rollover-options]]
  281. .Rollover Options
  282. [options="header"]
  283. |======
  284. | Name | Required | Default | Description
  285. | `max_size` | no | - | max index storage size.
  286. See <<byte-units, Byte Units>>
  287. for formatting
  288. | `max_docs` | no | - | max number of documents an
  289. index is to contain before
  290. rolling over.
  291. | `max_age` | no | - | max time elapsed from index
  292. creation. See
  293. <<time-units, Time Units>>
  294. for formatting
  295. |======
  296. At least one of `max_size`, `max_docs`, `max_age` or any combinations of the
  297. three are required to be specified.
  298. ===== Example: Rollover when index is too large
  299. This example rolls the index over when it is at least 100 gigabytes.
  300. [source,js]
  301. --------------------------------------------------
  302. PUT _ilm/policy/my_policy
  303. {
  304. "policy": {
  305. "phases": {
  306. "hot": {
  307. "actions": {
  308. "rollover" : {
  309. "max_size": "100GB"
  310. }
  311. }
  312. }
  313. }
  314. }
  315. }
  316. --------------------------------------------------
  317. // CONSOLE
  318. ===== Example: Rollover when index has too many documents
  319. This example rolls the index over when it contains at least
  320. 1000000 documents.
  321. [source,js]
  322. --------------------------------------------------
  323. PUT _ilm/policy/my_policy
  324. {
  325. "policy": {
  326. "phases": {
  327. "hot": {
  328. "actions": {
  329. "rollover" : {
  330. "max_docs": 1000000
  331. }
  332. }
  333. }
  334. }
  335. }
  336. }
  337. --------------------------------------------------
  338. // CONSOLE
  339. ===== Example: Rollover when index is too old
  340. This example rolls the index over when it has been created at least
  341. 7 days ago.
  342. [source,js]
  343. --------------------------------------------------
  344. PUT _ilm/policy/my_policy
  345. {
  346. "policy": {
  347. "phases": {
  348. "hot": {
  349. "actions": {
  350. "rollover" : {
  351. "max_age": "7d"
  352. }
  353. }
  354. }
  355. }
  356. }
  357. }
  358. --------------------------------------------------
  359. // CONSOLE
  360. ===== Example: Rollover when index is too old or too large
  361. This example rolls the index over when it has been created at least
  362. 7 days ago or it is at least 100 gigabytes. In this case, the index will be
  363. rolled over when any of the conditions is met.
  364. [source,js]
  365. --------------------------------------------------
  366. PUT _ilm/policy/my_policy
  367. {
  368. "policy": {
  369. "phases": {
  370. "hot": {
  371. "actions": {
  372. "rollover" : {
  373. "max_age": "7d",
  374. "max_size": "100GB"
  375. }
  376. }
  377. }
  378. }
  379. }
  380. }
  381. --------------------------------------------------
  382. // CONSOLE
  383. [[ilm-shrink-action]]
  384. ==== Shrink
  385. NOTE: Index will be be made read-only when this action is run
  386. (see: <<dynamic-index-settings,index.blocks.write>>)
  387. This action shrinks an existing index into a new index with fewer primary
  388. shards. It calls the <<indices-shrink-index,Shrink API>> to shrink the index.
  389. Since allocating all the primary shards of the index to one node is a
  390. prerequisite, this action will first allocate the primary shards to a valid
  391. node. After shrinking, it will swap aliases pointing to the original index
  392. into the new shrunken index. The new index will also have a new name:
  393. "shrink-<origin-index-name>". So if the original index was called "logs",
  394. then the new index will be named "shrink-logs".
  395. [[ilm-shrink-options]]
  396. .Shrink Options
  397. [options="header"]
  398. |======
  399. | Name | Required | Default | Description
  400. | `number_of_shards` | yes | - | The number of shards
  401. to shrink to. must be
  402. a factor of the number
  403. of shards in the
  404. source index.
  405. |======
  406. [source,js]
  407. --------------------------------------------------
  408. PUT _ilm/policy/my_policy
  409. {
  410. "policy": {
  411. "phases": {
  412. "warm": {
  413. "actions": {
  414. "shrink" : {
  415. "number_of_shards": 1
  416. }
  417. }
  418. }
  419. }
  420. }
  421. }
  422. --------------------------------------------------
  423. // CONSOLE
  424. === Full Policy
  425. beta[]
  426. With all of these actions, we can support complex management strategies for our
  427. indices. This policy will define an index that will start in the hot phase,
  428. rolling over every 20g or 7 days. After 30 days it enters the warm phase
  429. and increases the replicas to 2, force merges and shrinks. After 60 days
  430. it enters the cold phase and allocates to "cold" nodes, and after 90 days the
  431. index is deleted.
  432. [source,js]
  433. --------------------------------------------------
  434. PUT _ilm/policy/full_policy
  435. {
  436. "policy": {
  437. "phases": {
  438. "hot": {
  439. "actions": {
  440. "rollover": {
  441. "max_age": "7d",
  442. "max_size": "20G"
  443. }
  444. }
  445. },
  446. "warm": {
  447. "min_age": "30d",
  448. "actions": {
  449. "forcemerge": {
  450. "max_num_segments": 1
  451. },
  452. "shrink": {
  453. "number_of_shards": 1
  454. },
  455. "allocate": {
  456. "number_of_replicas": 2
  457. }
  458. }
  459. },
  460. "cold": {
  461. "min_age": "60d",
  462. "actions": {
  463. "allocate": {
  464. "require": {
  465. "type": "cold"
  466. }
  467. }
  468. }
  469. },
  470. "delete": {
  471. "min_age": "90d",
  472. "actions": {
  473. "delete": {}
  474. }
  475. }
  476. }
  477. }
  478. }
  479. --------------------------------------------------
  480. // CONSOLE