using-policies-rollover.asciidoc 5.3 KB

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