using-policies-rollover.asciidoc 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. [role="xpack"]
  2. [testenv="basic"]
  3. [[using-policies-rollover]]
  4. == Using policies to manage index rollover
  5. The rollover action enables you to automatically roll over to a new index based
  6. on the index size, document count, or age. When a rollover is triggered, a new
  7. index is created, the write alias is updated to point to the new index, and all
  8. subsequent updates are written to the new index.
  9. Rolling over to a new index based on size, document count, or age is preferable
  10. to time-based rollovers. Rolling over at an arbitrary time often results in
  11. many small indices, which can have a negative impact on performance and
  12. resource usage.
  13. You control when the rollover action is triggered by specifying one or more
  14. rollover parameters. The rollover is performed once any of the criteria are
  15. met. Because the criteria are checked periodically, the index might grow
  16. slightly beyond the specified threshold. To control how often the criteria are
  17. checked, specify the `indices.lifecycle.poll_interval` cluster setting.
  18. IMPORTANT: New indices created via rollover will not automatically inherit the
  19. policy used by the old index, and will not use any policy by default. Therefore,
  20. it is highly recommended to apply the policy via
  21. <<applying-policy-to-template,index template>>, including a Rollover alias
  22. setting, for your indices which specifies the policy you wish to use for each
  23. new index.
  24. The rollover action takes the following parameters:
  25. [[rollover-action-params]]
  26. .`rollover` Action Parameters
  27. [options="header"]
  28. |===
  29. |Name |Description
  30. |max_size |The maximum estimated size the primary shard of the index is allowed
  31. to grow to. Defaults to `null`. Optional.
  32. |max_docs |The maximum number of document the index should
  33. contain. Defaults to `null`. Optional.
  34. |max_age |The maximum age of the index. Defaults to `null`. Optional.
  35. |===
  36. These parameters are used to determine when the index is considered "full" and
  37. a rollover should be performed. Where multiple criteria are defined the
  38. rollover operation will be performed once any of the criteria are met.
  39. The following request defines a policy with a rollover action that triggers
  40. when the index size reaches 25GB. The old index is subsequently deleted after
  41. 30 days.
  42. NOTE: Once an index rolls over, {ilm} uses the timestamp of the rollover
  43. operation rather than the index creation time to evaluate when to move the
  44. index to the next phase. For indices that have rolled over, the `min_age`
  45. criteria specified for a phase is relative to the rollover time for indices. In
  46. this example, that means the index will be deleted 30 days after rollover, not
  47. 30 days from when the index was created.
  48. [source,js]
  49. --------------------------------------------------
  50. PUT /_ilm/policy/my_policy
  51. {
  52. "policy": {
  53. "phases": {
  54. "hot": {
  55. "actions": {
  56. "rollover": {
  57. "max_size": "25GB"
  58. }
  59. }
  60. },
  61. "delete": {
  62. "min_age": "30d",
  63. "actions": {
  64. "delete": {}
  65. }
  66. }
  67. }
  68. }
  69. }
  70. --------------------------------------------------
  71. // CONSOLE
  72. To use an {ilm} policy, you need to specify it in the index template used to
  73. create the indices. For example, the following template associates `my_policy`
  74. with indices created from the template `my_template`.
  75. [source,js]
  76. -----------------------
  77. PUT _template/my_template
  78. {
  79. "index_patterns": ["test-*"], <1>
  80. "settings": {
  81. "number_of_shards": 1,
  82. "number_of_replicas": 1,
  83. "index.lifecycle.name": "my_policy", <2>
  84. "index.lifecycle.rollover_alias": "test-alias" <3>
  85. }
  86. }
  87. -----------------------
  88. // CONSOLE
  89. <1> Template applies to all indices with the prefix test-
  90. <2> Associates my_policy with all indices created with this template
  91. <3> Rolls over the write alias test when the rollover action is triggered
  92. To be able to start using the policy for these `test-*` indexes we need to
  93. bootstrap the process by creating the first index.
  94. [source,js]
  95. -----------------------
  96. PUT test-000001 <1>
  97. {
  98. "aliases": {
  99. "test-alias":{
  100. "is_write_index": true <2>
  101. }
  102. }
  103. }
  104. -----------------------
  105. // CONSOLE
  106. <1> Creates the index called test-000001. The rollover action increments the
  107. suffix number for each subsequent index.
  108. <2> Designates this index as the write index for this alias.
  109. When the rollover is performed, the newly-created index is set as the write
  110. index for the rolled over alias. Documents sent to the alias are indexed into
  111. the new index, enabling indexing to continue uninterrupted.
  112. [[skipping-rollover]]
  113. === Skipping Rollover
  114. The `index.lifecycle.indexing_complete` setting indicates to {ilm} whether this
  115. index has already been rolled over. If it is set to `true`, that indicates that
  116. this index has already been rolled over and does not need to be rolled over
  117. again. Therefore, {ilm} will skip any Rollover Action configured in the
  118. associated lifecycle policy for this index. This is useful if you need to make
  119. an exception to your normal Lifecycle Policy and switching the alias to a
  120. different index by hand, but do not want to remove the index from {ilm}
  121. completely.
  122. This setting is set to `true` automatically by ILM upon the successful
  123. completion of a Rollover Action. However, it will be removed if
  124. <<ilm-remove-policy,the policy is removed>> from the index.
  125. IMPORTANT: If `index.lifecycle.indexing_complete` is set to `true` on an index,
  126. it will not be rolled over by {ilm}, but {ilm} will verify that this index is no
  127. longer the write index for the alias specified by
  128. `index.lifecycle.rollover_alias`. If that setting is missing, or if the index is
  129. still the write index for that alias, this index will be moved to the
  130. <<index-lifecycle-error-handling,error step>>.
  131. For example, if you wish to change the name of new indices while retaining
  132. previous data in accordance with your configured policy, you can create the
  133. template for the new index name pattern and the first index with the new name
  134. manually, change the write index of the alias using the <<indices-aliases, Index
  135. Aliases API>>, and set `index.lifecycle.indexing_complete` to `true` on the old
  136. index to indicate that it does not need to be rolled over. This way, {ilm} will
  137. continue to manage the old index in accordance with its existing policy, as well
  138. as the new one, with no interruption.