rollover-index.asciidoc 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. [[indices-rollover-index]]
  2. == Rollover Index
  3. The rollover index API rolls an alias over to a new index when the existing
  4. index is considered to be too large or too old.
  5. The API accepts a single alias name and a list of `conditions`. The alias
  6. must point to a single index only. If the index satisfies the specified
  7. conditions then a new index is created and the alias is switched to point to
  8. the new alias.
  9. [source,js]
  10. --------------------------------------------------
  11. PUT /logs-0001 <1>
  12. {
  13. "aliases": {
  14. "logs_write": {}
  15. }
  16. }
  17. POST logs_write/_rollover <2>
  18. {
  19. "conditions": {
  20. "max_age": "7d",
  21. "max_docs": 1000
  22. }
  23. }
  24. --------------------------------------------------
  25. // CONSOLE
  26. <1> Creates an index called `logs-0001` with the alias `logs_write`.
  27. <2> If the index pointed to by `logs_write` was created 7 or more days ago, or
  28. contains 1,000 or more documents, then the `logs-0002` index is created
  29. and the `logs_write` alias is updated to point to `logs-0002`.
  30. The above request might return the following response:
  31. [source,js]
  32. --------------------------------------------------
  33. {
  34. "old_index": "logs-0001",
  35. "new_index": "logs-0002",
  36. "rolled_over": true, <1>
  37. "dry_run": false, <2>
  38. "conditions": { <3>
  39. "[max_age: 7d]": false,
  40. "[max_docs: 1000]": true
  41. }
  42. }
  43. --------------------------------------------------
  44. <1> Whether the index was rolled over.
  45. <2> Whether the rollover was dry run.
  46. <3> The result of each condition.
  47. [float]
  48. === Naming the new index
  49. If the name of the existing index ends with `-` and a number -- e.g.
  50. `logs-0001` -- then the name of the new index will follow the same pattern,
  51. just incrementing the number (`logs-0002`).
  52. If the old name doesn't match this pattern then you must specify the name for
  53. the new index as follows:
  54. [source,js]
  55. --------------------------------------------------
  56. POST my_alias/_rollover/my_new_index_name
  57. {...}
  58. --------------------------------------------------
  59. [float]
  60. === Defining the new index
  61. The settings, mappings, and aliases for the new index are taken from any
  62. matching <<indices-templates,index templates>>. Additionally, you can specify
  63. `settings`, `mappings`, and `aliases` in the body of the request, just like the
  64. <<indices-create-index,create index>> API. Values specified in the request
  65. override any values set in matching index templates. For example, the following
  66. `rollover` request overrides the `index.number_of_shards` setting:
  67. [source,js]
  68. --------------------------------------------------
  69. PUT /logs-0001
  70. {
  71. "aliases": {
  72. "logs_write": {}
  73. }
  74. }
  75. POST logs_write/_rollover
  76. {
  77. "conditions" : {
  78. "max_age": "7d",
  79. "max_docs": 1000
  80. },
  81. "settings": {
  82. "index.number_of_shards": 2
  83. }
  84. }
  85. --------------------------------------------------
  86. // CONSOLE
  87. [float]
  88. === Dry run
  89. The rollover API supports `dry_run` mode, where request conditions can be
  90. checked without performing the actual rollover:
  91. [source,js]
  92. --------------------------------------------------
  93. PUT /logs-0001
  94. {
  95. "aliases": {
  96. "logs_write": {}
  97. }
  98. }
  99. POST logs_write/_rollover?dry_run
  100. {
  101. "conditions" : {
  102. "max_age": "7d",
  103. "max_docs": 1000
  104. }
  105. }
  106. --------------------------------------------------
  107. // CONSOLE