using-policies-rollover.asciidoc 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. [role="xpack"]
  2. [testenv="basic"]
  3. [[using-policies-rollover]]
  4. == Using policies to manage index rollover
  5. beta[]
  6. The rollover action enables you to automatically roll over to a new index based
  7. on the index size, document count, or age. When a rollover is triggered, a new
  8. index is created, the write alias is updated to point to the new index, and all
  9. subsequent updates are written to the new index.
  10. Rolling over to a new index based on size, document count, or age is preferable
  11. to time-based rollovers. Rolling over at an arbitrary time often results in
  12. many small indices, which can have a negative impact on performance and
  13. resource usage.
  14. You control when the rollover action is triggered by specifying one or more
  15. rollover parameters. The rollover is performed once any of the criteria are
  16. met. Because the criteria are checked periodically, the index might grow
  17. slightly beyond the specified threshold. To control how often the critera are
  18. checked, specify the `indices.lifecycle.poll_interval` cluster setting.
  19. IMPORTANT: New indices created via rollover will not automatically inherit the
  20. policy used by the old index, and will not use any policy by default. Therefore,
  21. it is highly recommended to apply the policy via
  22. <<applying-policy-to-template,index template>>, including a Rollover alias
  23. setting, for your indices which specifies the policy you wish to use for each
  24. new index.
  25. The rollover action takes the following parameters:
  26. .`rollover` Action Parameters
  27. |===
  28. |Name |Description
  29. |max_size |The maximum estimated size the index is allowed to grow
  30. to. Defaults tonull. Optional.
  31. |max_docs |The maximum number of document the index should
  32. contain. Defaults tonull. Optional.
  33. |max_age |The maximum age of the index. Defaults to `null`. Optional.
  34. |===
  35. These parameters are used to determine when the index is considered "full" and
  36. a rollover should be performed. Where multiple criteria are defined the
  37. rollover operation will be performed once any of the criteria are met.
  38. The following request defines a policy with a rollover action that triggers
  39. when the index size reaches 25GB. The old index is subsequently deleted after
  40. 30 days.
  41. NOTE: Once an index rolls over, {ilm} uses the timestamp of the rollover
  42. operation rather than the index creation time to evaluate when to move the
  43. index to the next phase. For indices that have rolled over, the `min_age`
  44. criteria specified for a phase is relative to the rollover time for indices. In
  45. this example, that means the index will be deleted 30 days after rollover, not
  46. 30 days from when the index was created.
  47. [source,js]
  48. --------------------------------------------------
  49. PUT /_ilm/policy/my_policy
  50. {
  51. "policy": {
  52. "phases": {
  53. "hot": {
  54. "actions": {
  55. "rollover": {
  56. "max_size": "25GB"
  57. }
  58. }
  59. },
  60. "delete": {
  61. "min_age": "30d",
  62. "actions": {
  63. "delete": {}
  64. }
  65. }
  66. }
  67. }
  68. }
  69. --------------------------------------------------
  70. // CONSOLE
  71. To use an {ilm} policy, you need to specify it in the index template used to
  72. create the indices. For example, the following template associates `my_policy`
  73. with indices created from the template `my_template`.
  74. [source,js]
  75. -----------------------
  76. PUT _template/my_template
  77. {
  78. "index_patterns": ["test-*"], <1>
  79. "settings": {
  80. "number_of_shards": 1,
  81. "number_of_replicas": 1,
  82. "index.lifecycle.name": "my_policy", <2>
  83. "index.lifecycle.rollover_alias": "test-alias" <3>
  84. }
  85. }
  86. -----------------------
  87. // CONSOLE
  88. <1> Template applies to all indices with the prefix test-
  89. <2> Associates my_policy with all indices created with this template
  90. <3> Rolls over the write alias test when the rollover action is triggered
  91. To be able to start using the policy for these `test-*` indexes we need to
  92. bootstrap the process by creating the first index.
  93. [source,js]
  94. -----------------------
  95. PUT test-000001 <1>
  96. {
  97. "aliases": {
  98. "test-alias":{
  99. "is_write_index": true <2>
  100. }
  101. }
  102. }
  103. -----------------------
  104. // CONSOLE
  105. <1> Creates the index called test-000001. The rollover action increments the
  106. suffix number for each subsequent index.
  107. <2> Designates this index as the write index for this alias.
  108. When the rollover is performed, the newly-created index is set as the write
  109. index for the rolled over alias. Documents sent to the alias are indexed into
  110. the new index, enabling indexing to continue uninterrupted.