split-index.asciidoc 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  1. [[indices-split-index]]
  2. == Split Index
  3. The split index API allows you to split an existing index into a new index,
  4. where each original primary shard is split into two or more primary shards in
  5. the new index.
  6. The number of times the index can be split (and the number of shards that each
  7. original shard can be split into) is determined by the
  8. `index.number_of_routing_shards` setting. The number of routing shards
  9. specifies the hashing space that is used internally to distribute documents
  10. across shards with consistent hashing. For instance, a 5 shard index with
  11. `number_of_routing_shards` set to `30` (`5 x 2 x 3`) could be split by a
  12. factor of `2` or `3`. In other words, it could be split as follows:
  13. * `5` -> `10` -> `30` (split by 2, then by 3)
  14. * `5` -> `15` -> `30` (split by 3, then by 2)
  15. * `5` -> `30` (split by 6)
  16. While you can set the `index.number_of_routing_shards` setting explicitly at
  17. index creation time, the default value depends upon the number of primary
  18. shards in the original index. The default is designed to allow you to split
  19. by factors of 2 up to a maximum of 1024 shards. However, the original number
  20. of primary shards must taken into account. For instance, an index created
  21. with 5 primary shards could be split into 10, 20, 40, 80, 160, 320, or a
  22. maximum of 740 shards (with a single split action or multiple split actions).
  23. If the original index contains one primary shard (or a multi-shard index has
  24. been <<indices-shrink-index,shrunk>> down to a single primary shard), then the
  25. index may by split into an arbitrary number of shards greater than 1. The
  26. properties of the default number of routing shards will then apply to the
  27. newly split index.
  28. Splitting works as follows:
  29. * First, it creates a new target index with the same definition as the source
  30. index, but with a larger number of primary shards.
  31. * Then it hard-links segments from the source index into the target index. (If
  32. the file system doesn't support hard-linking, then all segments are copied
  33. into the new index, which is a much more time consuming process.)
  34. * Once the low level files are created all documents will be `hashed` again to delete
  35. documents that belong to a different shard.
  36. * Finally, it recovers the target index as though it were a closed index which
  37. had just been re-opened.
  38. [float]
  39. === Preparing an index for splitting
  40. Create a new index:
  41. [source,js]
  42. --------------------------------------------------
  43. PUT my_source_index
  44. {
  45. "settings": {
  46. "index.number_of_shards" : 1
  47. }
  48. }
  49. -------------------------------------------------
  50. // CONSOLE
  51. In order to split an index, the index must be marked as read-only,
  52. and have <<cluster-health,health>> `green`.
  53. This can be achieved with the following request:
  54. [source,js]
  55. --------------------------------------------------
  56. PUT /my_source_index/_settings
  57. {
  58. "settings": {
  59. "index.blocks.write": true <1>
  60. }
  61. }
  62. --------------------------------------------------
  63. // CONSOLE
  64. // TEST[continued]
  65. <1> Prevents write operations to this index while still allowing metadata
  66. changes like deleting the index.
  67. [float]
  68. === Splitting an index
  69. To split `my_source_index` into a new index called `my_target_index`, issue
  70. the following request:
  71. [source,js]
  72. --------------------------------------------------
  73. POST my_source_index/_split/my_target_index
  74. {
  75. "settings": {
  76. "index.number_of_shards": 2
  77. }
  78. }
  79. --------------------------------------------------
  80. // CONSOLE
  81. // TEST[continued]
  82. The above request returns immediately once the target index has been added to
  83. the cluster state -- it doesn't wait for the split operation to start.
  84. [IMPORTANT]
  85. =====================================
  86. Indices can only be split if they satisfy the following requirements:
  87. * the target index must not exist
  88. * The source index must have fewer primary shards than the target index.
  89. * The number of primary shards in the target index must be a factor of the
  90. number of primary shards in the source index.
  91. * The node handling the split process must have sufficient free disk space to
  92. accommodate a second copy of the existing index.
  93. =====================================
  94. The `_split` API is similar to the <<indices-create-index, `create index` API>>
  95. and accepts `settings` and `aliases` parameters for the target index:
  96. [source,js]
  97. --------------------------------------------------
  98. POST my_source_index/_split/my_target_index
  99. {
  100. "settings": {
  101. "index.number_of_shards": 5 <1>
  102. },
  103. "aliases": {
  104. "my_search_indices": {}
  105. }
  106. }
  107. --------------------------------------------------
  108. // CONSOLE
  109. // TEST[s/^/PUT my_source_index\n{"settings": {"index.blocks.write": true, "index.number_of_shards": "1"}}\n/]
  110. <1> The number of shards in the target index. This must be a factor of the
  111. number of shards in the source index.
  112. NOTE: Mappings may not be specified in the `_split` request, and all
  113. `index.analysis.*` and `index.similarity.*` settings will be overwritten with
  114. the settings from the source index.
  115. [float]
  116. === Monitoring the split process
  117. The split process can be monitored with the <<cat-recovery,`_cat recovery`
  118. API>>, or the <<cluster-health, `cluster health` API>> can be used to wait
  119. until all primary shards have been allocated by setting the `wait_for_status`
  120. parameter to `yellow`.
  121. The `_split` API returns as soon as the target index has been added to the
  122. cluster state, before any shards have been allocated. At this point, all
  123. shards are in the state `unassigned`. If, for any reason, the target index
  124. can't be allocated, its primary shard will remain `unassigned` until it
  125. can be allocated on that node.
  126. Once the primary shard is allocated, it moves to state `initializing`, and the
  127. split process begins. When the split operation completes, the shard will
  128. become `active`. At that point, Elasticsearch will try to allocate any
  129. replicas and may decide to relocate the primary shard to another node.
  130. [float]
  131. === Wait For Active Shards
  132. Because the split operation creates a new index to split the shards to,
  133. the <<create-index-wait-for-active-shards,wait for active shards>> setting
  134. on index creation applies to the split index action as well.