reindex_upgrade.asciidoc 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  1. [[reindex-upgrade]]
  2. == Reindex before upgrading
  3. {es} can read indices created in the previous major version. If you
  4. have indices created in 5.x or before, you must reindex or delete them
  5. before upgrading to {version}. {es} nodes will fail to start if
  6. incompatible indices are present. Snapshots of 5.x or earlier indices cannot be
  7. restored to a 7.x cluster even if they were created by a 6.x cluster.
  8. This restriction also applies to the internal indices that are used by
  9. {kib} and the {xpack} features. Therefore, before you can use {kib} and
  10. {xpack} features in {version}, you must ensure the internal indices have a
  11. compatible index structure.
  12. You have two options for reindexing old indices:
  13. * <<reindex-upgrade-inplace, Reindex in place>> on your 6.x cluster before upgrading.
  14. * Create a new {version} cluster and <<reindex-upgrade-remote, Reindex from remote>>.
  15. This enables you to reindex indices that reside on clusters running any version of {es}.
  16. .Upgrading time-based indices
  17. *******************************************
  18. If you use time-based indices, you likely won't need to carry
  19. pre-6.x indices forward to {version}. Data in time-based indices
  20. generally becomes less useful as time passes and are
  21. deleted as they age past your retention period.
  22. Unless you have an unusually long retention period, you can just
  23. wait to upgrade to 6.x until all of your pre-6.x indices have
  24. been deleted.
  25. *******************************************
  26. [[reindex-upgrade-inplace]]
  27. === Reindex in place
  28. You can use the Upgrade Assistant in {kib} 6.8 to automatically reindex 5.x
  29. indices you need to carry forward to {version}.
  30. To manually reindex your old indices in place:
  31. . Create an index with 7.x compatible mappings.
  32. . Set the `refresh_interval` to `-1` and the `number_of_replicas` to `0` for
  33. efficient reindexing.
  34. . Use the <<docs-reindex,`reindex` API>> to copy documents from the
  35. 5.x index into the new index. You can use a script to perform any necessary
  36. modifications to the document data and metadata during reindexing.
  37. . Reset the `refresh_interval` and `number_of_replicas` to the values
  38. used in the old index.
  39. . Wait for the index status to change to `green`.
  40. . In a single <<indices-aliases,update aliases>> request:
  41. .. Delete the old index.
  42. .. Add an alias with the old index name to the new index.
  43. .. Add any aliases that existed on the old index to the new index.
  44. ifdef::include-xpack[]
  45. [TIP]
  46. ====
  47. If you use {ml-features} and your {ml} indices were created before
  48. {prev-major-version}, you must temporarily halt the tasks associated with your
  49. {ml} jobs and {dfeeds} and prevent new jobs from opening during the reindex. Use
  50. the <<ml-set-upgrade-mode,set upgrade mode API>> or
  51. {stack-ov}/stopping-ml.html[stop all {dfeeds} and close all {ml} jobs].
  52. If you use {es} {security-features}, before you reindex `.security*` internal
  53. indices it is a good idea to create a temporary superuser account in the `file`
  54. realm.
  55. . On a single node, add a temporary superuser account to the `file` realm. For
  56. example, run the <<users-command,elasticsearch-users useradd>> command:
  57. +
  58. --
  59. [source,sh]
  60. ----------------------------------------------------------
  61. bin/elasticsearch-users useradd <user_name> \
  62. -p <password> -r superuser
  63. ----------------------------------------------------------
  64. --
  65. . Use these credentials when you reindex the `.security*` index. That is to say,
  66. use them to log into {kib} and run the Upgrade Assistant or to call the
  67. reindex API. You can use your regular administration credentials to
  68. reindex the other internal indices.
  69. . Delete the temporary superuser account from the file realm. For
  70. example, run the {ref}/users-command.html[elasticsearch-users userdel] command:
  71. +
  72. --
  73. [source,sh]
  74. ----------------------------------------------------------
  75. bin/elasticsearch-users userdel <user_name>
  76. ----------------------------------------------------------
  77. --
  78. For more information, see <<configuring-file-realm>>.
  79. ====
  80. endif::include-xpack[]
  81. [[reindex-upgrade-remote]]
  82. === Reindex from a remote cluster
  83. You can use <<reindex-from-remote,reindex from remote>> to migrate indices from
  84. your old cluster to a new {version} cluster. This enables you move to {version}
  85. from a pre-6.8 cluster without interrupting service.
  86. [WARNING]
  87. =============================================
  88. {es} provides backwards compatibility support that enables
  89. indices from the previous major version to be upgraded to the
  90. current major version. Skipping a major version means that you must
  91. resolve any backward compatibility issues yourself.
  92. ifdef::include-xpack[]
  93. If you use {ml-features} and you're migrating indices from a 6.5 or earlier
  94. cluster, the job and {dfeed} configuration information are not stored in an
  95. index. You must recreate your {ml} jobs in the new cluster. If you are migrating
  96. from a 6.6 or later cluster, it is a good idea to temporarily halt the tasks
  97. associated with your {ml} jobs and {dfeeds} to prevent inconsistencies between
  98. different {ml} indices that are reindexed at slightly different times. Use the
  99. <<ml-set-upgrade-mode,set upgrade mode API>> or
  100. {stack-ov}/stopping-ml.html[stop all {dfeeds} and close all {ml} jobs].
  101. endif::include-xpack[]
  102. =============================================
  103. To migrate your indices:
  104. . Set up a new {version} cluster and add the existing cluster to the
  105. `reindex.remote.whitelist` in `elasticsearch.yml`.
  106. +
  107. --
  108. [source,yaml]
  109. --------------------------------------------------
  110. reindex.remote.whitelist: oldhost:9200
  111. --------------------------------------------------
  112. [NOTE]
  113. =============================================
  114. The new cluster doesn't have to start fully-scaled out. As you migrate
  115. indices and shift the load to the new cluster, you can add nodes to the new
  116. cluster and remove nodes from the old one.
  117. =============================================
  118. --
  119. . For each index that you need to migrate to the new cluster:
  120. .. Create an index the appropriate mappings and settings. Set the
  121. `refresh_interval` to `-1` and set `number_of_replicas` to `0` for
  122. faster reindexing.
  123. .. Use the <<docs-reindex,`reindex` API>> to pull documents from the
  124. remote index into the new {version} index:
  125. +
  126. --
  127. [source,js]
  128. --------------------------------------------------
  129. POST _reindex
  130. {
  131. "source": {
  132. "remote": {
  133. "host": "http://oldhost:9200",
  134. "username": "user",
  135. "password": "pass"
  136. },
  137. "index": "source",
  138. "query": {
  139. "match": {
  140. "test": "data"
  141. }
  142. }
  143. },
  144. "dest": {
  145. "index": "dest"
  146. }
  147. }
  148. --------------------------------------------------
  149. // CONSOLE
  150. // TEST[setup:host]
  151. // TEST[s/^/PUT source\n/]
  152. // TEST[s/oldhost:9200",/\${host}"/]
  153. // TEST[s/"username": "user",//]
  154. // TEST[s/"password": "pass"//]
  155. If you run the reindex job in the background by setting `wait_for_completion`
  156. to `false`, the reindex request returns a `task_id` you can use to
  157. monitor progress of the reindex job with the <<tasks,task API>>:
  158. `GET _tasks/TASK_ID`.
  159. --
  160. .. When the reindex job completes, set the `refresh_interval` and
  161. `number_of_replicas` to the desired values (the default settings are
  162. `30s` and `1`).
  163. .. Once reindexing is complete and the status of the new index is `green`,
  164. you can delete the old index.