using-policies-rollover.asciidoc 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  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 critera are
  17. checked, specify the `indices.lifecycle.poll_interval` cluster setting.
  18. The rollover action takes the following parameters:
  19. .`rollover` Action Parameters
  20. |===
  21. |Name |Description
  22. |max_size |The maximum estimated size the index is allowed to grow
  23. to. Defaults tonull. Optional.
  24. |max_docs |The maximum number of document the index should
  25. contain. Defaults tonull. Optional.
  26. |max_age |The maximum age of the index. Defaults to `null`. Optional.
  27. |===
  28. These parameters are used to determine when the index is considered "full" and
  29. a rollover should be performed. Where multiple criteria are defined the
  30. rollover operation will be performed once any of the criteria are met.
  31. The following request defines a policy with a rollover action that triggers
  32. when the index size reaches 25GB. The old index is subsequently deleted after
  33. 30 days.
  34. NOTE: Once an index rolls over, {ilm} uses the timestamp of the rollover
  35. operation rather than the index creation time to evaluate when to move the
  36. index to the next phase. For indices that have rolled over, the `minimum_age`
  37. criteria specified for a phase is relative to the rollover time for indices. In
  38. this example, that means the index will be deleted 30 days after rollover, not
  39. 30 days from when the index was created.
  40. [source,js]
  41. --------------------------------------------------
  42. PUT /_ilm/my_policy
  43. {
  44. "policy": {
  45. "phases": {
  46. "hot": {
  47. "actions": {
  48. "rollover": {
  49. "max_size": "25GB"
  50. }
  51. }
  52. },
  53. "delete": {
  54. "minimum_age": "30d",
  55. "actions": {
  56. "delete": {}
  57. }
  58. }
  59. }
  60. }
  61. }
  62. --------------------------------------------------
  63. // CONSOLE
  64. To use an {ilm} policy, you need to specify it in the index template used to
  65. create the indices. For example, the following template associates `my_policy`
  66. with indices created from the template `my_template`.
  67. [source,js]
  68. -----------------------
  69. PUT _template/my_template
  70. {
  71. "index_patterns": ["test-*"], <1>
  72. "settings": {
  73. "number_of_shards": 1,
  74. "number_of_replicas": 1,
  75. "index.lifecycle.name": "my_policy", <2>
  76. "index.lifecycle.rollover_alias": "test-alias" <3>
  77. }
  78. }
  79. -----------------------
  80. // CONSOLE
  81. <1> Template applies to all indices with the prefix test-
  82. <2> Associates my_policy with all indices created with this template
  83. <3> Rolls over the write alias test when the rollover action is triggered
  84. To be able to start using the policy for these `test-*` indexes we need to
  85. bootstrap the process by creating the first index.
  86. [source,js]
  87. -----------------------
  88. PUT test-000001 <1>
  89. {
  90. "aliases": {
  91. "test-alias":{
  92. "is_write_index": true <2>
  93. }
  94. }
  95. }
  96. -----------------------
  97. // CONSOLE
  98. <1> Creates the index called test-000001. The rollover action increments the
  99. suffix number for each subsequent index.
  100. <2> Designates this index as the write index for this alias.
  101. When the rollover is performed, the newly-created index is set as the write
  102. index for the rolled over alias. Documents sent to the alias are indexed into
  103. the new index, enabling indexing to continue uninterrupted.