rollover-index.asciidoc 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. [[indices-rollover-index]]
  2. == Rollover Index
  3. The rollover index API allows to switch the index pointed to by an alias given some predicates.
  4. In order to rollover an index, the provided alias has to point to a single index. Upon satisfying
  5. any of the predicates, the alias is switched to point to a new index, creating the index if it
  6. does not exist. The rollover API requires the old concrete index name to have `{index_prefix}-{num}`
  7. format, as rollover index name is generated following `{index_prefix}-{num+1}` format.
  8. This API is syntactic sugar for changing the index pointed to by an alias given some predicate.
  9. The rollover API must be used against an alias that points to a single index:
  10. [source,js]
  11. --------------------------------------------------
  12. $ curl -XPUT 'http://localhost:9200/index-1/' -d '{
  13. "aliases" : {
  14. "index_alias": {}
  15. }
  16. }'
  17. --------------------------------------------------
  18. To rollover `index_alias` to point to a new index:
  19. [source,js]
  20. --------------------------------------------------
  21. $ curl -XPOST 'http://localhost:9200/index_alias/_rollover' -d '{
  22. "conditions" : {
  23. "max_age": "7d", <1>
  24. "max_docs": 1000 <2>
  25. }
  26. }'
  27. --------------------------------------------------
  28. <1> Sets a condition that the index has to be at least 7 days old
  29. <2> Sets a condition that the index has to have at least a 1000 documents
  30. The API call above switches the index pointed to by `index_alias` from `index-1` to `index-2`, if any
  31. of the conditions are met. If `index-2` does not exist, it is created (using matching <<indices-templates>>
  32. if available). The API call returns immediately if none of the conditions are met.
  33. The `_rollover` API is similar to <<indices-create-index>> and accepts `settings`, `mappings` and `aliases`
  34. to override the index create request for a non-existent rolled over index.
  35. [source,js]
  36. --------------------------------------------------
  37. $ curl -XPOST 'http://localhost:9200/index_alias/_rollover' -d '{
  38. "conditions" : {
  39. "max_age": "7d",
  40. "max_docs": 1000
  41. },
  42. "settings": { <1>
  43. "index.number_of_shards": 2
  44. }
  45. }'
  46. --------------------------------------------------
  47. <1> Set settings to override matching index template, `mappings` and `aliases` can also be provided.
  48. Using the http `GET` method for the API runs the rollover in simulated mode, where request conditions can be
  49. checked without performing the actual rollover. Setting `simulate=true` as a request parameter also runs
  50. the request in simulated mode.
  51. An example response for the index rollover API:
  52. [source,js]
  53. --------------------------------------------------
  54. {
  55. "old_index": "index-1", <1>
  56. "new_index": "index-2", <2>
  57. "rolled_over": true, <3>
  58. "simulated": false, <4>
  59. "rollover_index_created": true, <5>
  60. "conditions": { <6>
  61. "[max_age: 7d]": true,
  62. "[max_docs: 1000]": true
  63. }
  64. }
  65. --------------------------------------------------
  66. <1> name of the index the alias was pointing to
  67. <2> name of the index the alias currently points to
  68. <3> whether the alias switch was successful
  69. <4> whether the rollover was dry run
  70. <5> whether the rolled over index had to be explicitly created
  71. <6> status of the evaluated request conditions