reindex_upgrade.asciidoc 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  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.7 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
  49. {stack-ov}/stopping-ml.html[stop all {dfeeds} and close all {ml} jobs] before
  50. you reindex the indices.
  51. If you use {es} {security-features}, before you reindex `.security*` internal
  52. indices it is a good idea to create a temporary superuser account in the `file`
  53. realm.
  54. . On a single node, add a temporary superuser account to the `file` realm. For
  55. example, run the <<users-command,elasticsearch-users useradd>> command:
  56. +
  57. --
  58. [source,sh]
  59. ----------------------------------------------------------
  60. bin/elasticsearch-users useradd <user_name> \
  61. -p <password> -r superuser
  62. ----------------------------------------------------------
  63. --
  64. . Use these credentials when you reindex the `.security*` index. That is to say,
  65. use them to log into {kib} and run the Upgrade Assistant or to call the
  66. reindex API. You can use your regular administration credentials to
  67. reindex the other internal indices.
  68. . Delete the temporary superuser account from the file realm. For
  69. example, run the {ref}/users-command.html[elasticsearch-users userdel] command:
  70. +
  71. --
  72. [source,sh]
  73. ----------------------------------------------------------
  74. bin/elasticsearch-users userdel <user_name>
  75. ----------------------------------------------------------
  76. --
  77. For more information, see <<configuring-file-realm>>.
  78. ====
  79. endif::include-xpack[]
  80. [[reindex-upgrade-remote]]
  81. === Reindex from a remote cluster
  82. You can use <<reindex-from-remote,reindex from remote>> to migrate indices from
  83. your old cluster to a new {version} cluster. This enables you move to {version}
  84. from a pre-6.7 cluster without interrupting service.
  85. [WARNING]
  86. =============================================
  87. {es} provides backwards compatibility support that enables
  88. indices from the previous major version to be upgraded to the
  89. current major version. Skipping a major version means that you must
  90. resolve any backward compatibility issues yourself.
  91. =============================================
  92. To migrate your indices:
  93. . Set up a new {version} cluster and add the existing cluster to the
  94. `reindex.remote.whitelist` in `elasticsearch.yml`.
  95. +
  96. --
  97. [source,yaml]
  98. --------------------------------------------------
  99. reindex.remote.whitelist: oldhost:9200
  100. --------------------------------------------------
  101. [NOTE]
  102. =============================================
  103. The new cluster doesn't have to start fully-scaled out. As you migrate
  104. indices and shift the load to the new cluster, you can add nodes to the new
  105. cluster and remove nodes from the old one.
  106. =============================================
  107. --
  108. . For each index that you need to migrate to the new cluster:
  109. .. Create an index the appropriate mappings and settings. Set the
  110. `refresh_interval` to `-1` and set `number_of_replicas` to `0` for
  111. faster reindexing.
  112. .. Use the <<docs-reindex,`reindex` API>> to pull documents from the
  113. remote index into the new {version} index:
  114. +
  115. --
  116. [source,js]
  117. --------------------------------------------------
  118. POST _reindex
  119. {
  120. "source": {
  121. "remote": {
  122. "host": "http://oldhost:9200",
  123. "username": "user",
  124. "password": "pass"
  125. },
  126. "index": "source",
  127. "query": {
  128. "match": {
  129. "test": "data"
  130. }
  131. }
  132. },
  133. "dest": {
  134. "index": "dest"
  135. }
  136. }
  137. --------------------------------------------------
  138. // CONSOLE
  139. // TEST[setup:host]
  140. // TEST[s/^/PUT source\n/]
  141. // TEST[s/oldhost:9200",/\${host}"/]
  142. // TEST[s/"username": "user",//]
  143. // TEST[s/"password": "pass"//]
  144. If you run the reindex job in the background by setting `wait_for_completion`
  145. to `false`, the reindex request returns a `task_id` you can use to
  146. monitor progress of the reindex job with the <<tasks,task API>>:
  147. `GET _tasks/TASK_ID`.
  148. --
  149. .. When the reindex job completes, set the `refresh_interval` and
  150. `number_of_replicas` to the desired values (the default settings are
  151. `30s` and `1`).
  152. .. Once reindexing is complete and the status of the new index is `green`,
  153. you can delete the old index.