Skip to content

Commit 5833616

Browse files
committed
[DOCS] Edit reindex API examples
1 parent 83fe2ed commit 5833616

File tree

3 files changed

+651
-52
lines changed

3 files changed

+651
-52
lines changed

docs/reference/elasticsearch/rest-apis/reindex-data-stream.md

Lines changed: 18 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -1,62 +1,29 @@
11
---
2-
navigation_title: "Reindex data stream"
2+
navigation_title: "Reindex data streams"
33
mapped_pages:
44
- https://www.elastic.co/guide/en/elasticsearch/reference/current/data-stream-reindex-api.html
5-
# That link will 404 until 8.18 is current
6-
# (see https://www.elastic.co/guide/en/elasticsearch/reference/8.18/data-stream-reindex-api.html)
75
applies_to:
86
stack: all
97
---
108

11-
# Reindex data stream API [data-stream-reindex-api]
9+
# Reindex data stream examples [data-stream-reindex-api]
1210

13-
14-
::::{admonition} New API reference
1511
For the most up-to-date API details, refer to [Migration APIs](https://www.elastic.co/docs/api/doc/elasticsearch/group/endpoint-migration).
1612

17-
::::
18-
19-
2013
::::{tip}
21-
These APIs are designed for indirect use by {{kib}}'s **Upgrade Assistant**. We strongly recommend you use the **Upgrade Assistant** to upgrade from 8.17 to {{version}}. For upgrade instructions, refer to [Upgrading to Elastic {{version}}](docs-content://deploy-manage/upgrade/deployment-or-cluster.md).
14+
The reindex data stream API are designed for indirect use by {{kib}}'s **Upgrade Assistant**. We strongly recommend you use the **Upgrade Assistant** to perform upgrades. Refer to [](docs-content://deploy-manage/upgrade.md).
2215
::::
2316

24-
2517
The reindex data stream API is used to upgrade the backing indices of a data stream to the most recent major version. It works by reindexing each backing index into a new index, then replacing the original backing index with its replacement and deleting the original backing index. The settings and mappings from the original backing indices are copied to the resulting backing indices.
2618

27-
This api runs in the background because reindexing all indices in a large data stream is expected to take a large amount of time and resources. The endpoint will return immediately and a persistent task will be created to run in the background. The current status of the task can be checked with the [reindex status API](https://www.elastic.co/docs/api/doc/elasticsearch/operation/operation-indices-get-migrate-reindex-status). This status will be available for 24 hours after the task completes, whether it finished successfully or failed. If the status is still available for a task, the task must be cancelled before it can be re-run. A running or recently completed data stream reindex task can be cancelled using the [reindex cancel API](https://www.elastic.co/docs/api/doc/elasticsearch/operation/operation-indices-cancel-migrate-reindex).
28-
29-
## {{api-request-title}} [data-stream-reindex-api-request]
30-
31-
`POST /_migration/reindex`
32-
33-
34-
## {{api-prereq-title}} [data-stream-reindex-api-prereqs]
35-
36-
* If the {{es}} {{security-features}} are enabled, you must have the `manage` [index privilege](docs-content://deploy-manage/users-roles/cluster-or-deployment-auth/elasticsearch-privileges.md#privileges-list-indices) for the data stream.
37-
38-
39-
## {{api-request-body-title}} [data-stream-reindex-body]
40-
41-
`source`
42-
: `index`
43-
: (Required, string) The name of the data stream to upgrade.
44-
45-
46-
`mode`
47-
: (Required, enum) Set to `upgrade` to upgrade the data stream in-place, using the same source and destination data stream. Each out-of-date backing index will be reindexed. Then the new backing index is swapped into the data stream and the old index is deleted. Currently, the only allowed value for this parameter is `upgrade`.
48-
19+
This API runs in the background because reindexing all indices in a large data stream is expected to take a large amount of time and resources. The endpoint will return immediately and a persistent task will be created to run in the background. The current status of the task can be checked with the [reindex status API](https://www.elastic.co/docs/api/doc/elasticsearch/operation/operation-indices-get-migrate-reindex-status). This status will be available for 24 hours after the task completes, whether it finished successfully or failed. If the status is still available for a task, the task must be cancelled before it can be re-run. A running or recently completed data stream reindex task can be cancelled using the [reindex cancel API](https://www.elastic.co/docs/api/doc/elasticsearch/operation/operation-indices-cancel-migrate-reindex).
4920

5021
## Settings [reindex-data-stream-api-settings]
5122

52-
You can use the following settings to control the behavior of the reindex data stream API:
53-
23+
You can use settings to control the behavior of the reindex data stream API.
24+
Refer to [](/reference/elasticsearch/configuration-reference/data-stream-lifecycle-settings.md)
5425
$$$migrate_max_concurrent_indices_reindexed_per_data_stream-setting$$$
55-
`migrate.max_concurrent_indices_reindexed_per_data_stream` ([Dynamic](docs-content://deploy-manage/deploy/self-managed/configure-elasticsearch.md#dynamic-cluster-setting)) The number of backing indices within a given data stream which will be reindexed concurrently. Defaults to `1`.
56-
5726
$$$migrate_data_stream_reindex_max_request_per_second-setting$$$
58-
`migrate.data_stream_reindex_max_request_per_second` ([Dynamic](docs-content://deploy-manage/deploy/self-managed/configure-elasticsearch.md#dynamic-cluster-setting)) The average maximum number of documents within a given backing index to reindex per second. Defaults to `1000`, though can be any decimal number greater than `0`. To remove throttling, set to `-1`. This setting can be used to throttle the reindex process and manage resource usage. Consult the [reindex throttle docs](https://www.elastic.co/docs/api/doc/elasticsearch/operation/operation-reindex#docs-reindex-throttle) for more information.
59-
6027

6128
## {{api-examples-title}} [reindex-data-stream-api-example]
6229

@@ -66,7 +33,7 @@ Assume we have a data stream `my-data-stream` with the following backing indices
6633
* .ds-my-data-stream-2025.01.23-000002
6734
* .ds-my-data-stream-2025.01.23-000003
6835

69-
Lets also assume that `.ds-my-data-stream-2025.01.23-000003` is the write index. If {{es}} is version 8.x and we wish to upgrade to major version 9.x, the version 7.x indices must be upgraded in preparation. We can use this API to reindex a data stream with version 7.x backing indices and make them version 8 backing indices.
36+
Let's also assume that `.ds-my-data-stream-2025.01.23-000003` is the write index. If {{es}} is version 8.x and we wish to upgrade to major version 9.x, the version 7.x indices must be upgraded in preparation. We can use this API to reindex a data stream with version 7.x backing indices and make them version 8 backing indices.
7037

7138
Start by calling the API:
7239

@@ -84,7 +51,7 @@ POST _migration/reindex
8451

8552
As this task runs in the background this API will return immediately. The task will do the following.
8653

87-
First, the data stream is rolled over. So that no documents are lost during the reindex, we add [write blocks](/reference/elasticsearch/index-settings/index-block.md) to the existing backing indices before reindexing them. Since a data streams write index cannot have a write block, the data stream is must be rolled over. This will produce a new write index, `.ds-my-data-stream-2025.01.23-000004`; which has an 8.x version and thus does not need to be upgraded.
54+
First, the data stream is rolled over. So that no documents are lost during the reindex, we add [write blocks](/reference/elasticsearch/index-settings/index-block.md) to the existing backing indices before reindexing them. Since a data stream's write index cannot have a write block, the data stream is must be rolled over. This will produce a new write index, `.ds-my-data-stream-2025.01.23-000004`; which has an 8.x version and thus does not need to be upgraded.
8855

8956
Once the data stream has a write index with an 8.x version we can proceed with reindexing the old indices. For each of the version 7.x indices, we now do the following:
9057

@@ -97,7 +64,7 @@ Once the data stream has a write index with an 8.x version we can proceed with r
9764
* Replace the old index in the data stream with the new index, using the [modify data streams API](https://www.elastic.co/docs/api/doc/elasticsearch/operation/operation-indices-modify-data-stream).
9865
* Finally, the old backing index is deleted.
9966

100-
By default only one backing index will be processed at a time. This can be modified using the [`migrate_max_concurrent_indices_reindexed_per_data_stream-setting` setting](#migrate_max_concurrent_indices_reindexed_per_data_stream-setting).
67+
By default only one backing index will be processed at a time. This can be modified using the [`migrate_max_concurrent_indices_reindexed_per_data_stream-setting` setting](/reference/elasticsearch/configuration-reference/data-stream-lifecycle-settings.md).
10168

10269
While the reindex data stream task is running, we can inspect the current status using the [reindex status API](https://www.elastic.co/docs/api/doc/elasticsearch/operation/operation-indices-get-migrate-reindex-status):
10370

@@ -126,11 +93,11 @@ For the above example, the following would be a possible status:
12693
}
12794
```
12895

129-
This output means that the first backing index, `.ds-my-data-stream-2025.01.23-000001`, is currently being processed, and none of the backing indices have yet completed. Notice that `total_indices_in_data_stream` has a value of `4`, because after the rollover, there are 4 indices in the data stream. But the new write index has an 8.x version, and thus doesnt need to be reindexed, so `total_indices_requiring_upgrade` is only 3.
96+
This output means that the first backing index, `.ds-my-data-stream-2025.01.23-000001`, is currently being processed, and none of the backing indices have yet completed. Notice that `total_indices_in_data_stream` has a value of `4`, because after the rollover, there are 4 indices in the data stream. But the new write index has an 8.x version, and thus doesn't need to be reindexed, so `total_indices_requiring_upgrade` is only 3.
13097

131-
### Cancelling and Restarting [reindex-data-stream-cancel-restart]
98+
### Cancelling and restarting [reindex-data-stream-cancel-restart]
13299

133-
The [reindex datastream settings](#reindex-data-stream-api-settings) provide a few ways to control the performance and resource usage of a reindex task. This example shows how we can stop a running reindex task, modify the settings, and restart the task.
100+
The reindex datastream settings provide a few ways to control the performance and resource usage of a reindex task. This example shows how we can stop a running reindex task, modify the settings, and restart the task.
134101

135102
Continuing with the above example, assume the reindexing task has not yet completed, and the [reindex status API](https://www.elastic.co/docs/api/doc/elasticsearch/operation/operation-indices-get-migrate-reindex-status) returns the following:
136103

@@ -153,9 +120,9 @@ Continuing with the above example, assume the reindexing task has not yet comple
153120
}
154121
```
155122

156-
Lets assume the task has been running for a long time. By default, we throttle how many requests the reindex operation can execute per second. This keeps the reindex process from consuming too many resources. But the default value of `1000` request per second will not be correct for all use cases. The [`migrate.data_stream_reindex_max_request_per_second` setting](#migrate_data_stream_reindex_max_request_per_second-setting) can be used to increase or decrease the number of requests per second, or to remove the throttle entirely.
123+
Let's assume the task has been running for a long time. By default, we throttle how many requests the reindex operation can execute per second. This keeps the reindex process from consuming too many resources. But the default value of `1000` request per second will not be correct for all use cases. The [`migrate.data_stream_reindex_max_request_per_second` setting](/reference/elasticsearch/configuration-reference/data-stream-lifecycle-settings.md) can be used to increase or decrease the number of requests per second, or to remove the throttle entirely.
157124

158-
Changing this setting wont have an effect on the backing index that is currently being reindexed. For example, changing the setting wont have an effect on `.ds-my-data-stream-2025.01.23-000002`, but would have an effect on the next backing index.
125+
Changing this setting won't have an effect on the backing index that is currently being reindexed. For example, changing the setting won't have an effect on `.ds-my-data-stream-2025.01.23-000002`, but would have an effect on the next backing index.
159126

160127
But in the above status, `.ds-my-data-stream-2025.01.23-000002` has values of 1000 and 10M for the `reindexed_doc_count` and `total_doc_count`, respectively. This means it has only reindexed 0.01% of the documents in the index. It might be a good time to cancel the run and optimize some settings without losing much work. So we call the [cancel API](https://www.elastic.co/docs/api/doc/elasticsearch/operation/operation-indices-cancel-migrate-reindex):
161128

@@ -174,7 +141,7 @@ PUT /_cluster/settings
174141
}
175142
```
176143

177-
The [original reindex command](#reindex-data-stream-start) can now be used to restart reindexing. Because the first backing index, `.ds-my-data-stream-2025.01.23-000001`, has already been reindexed and thus is already version 8.x, it will be skipped. The task will start by reindexing `.ds-my-data-stream-2025.01.23-000002` again from the beginning.
144+
The original reindex command can now be used to restart reindexing. Because the first backing index, `.ds-my-data-stream-2025.01.23-000001`, has already been reindexed and thus is already version 8.x, it will be skipped. The task will start by reindexing `.ds-my-data-stream-2025.01.23-000002` again from the beginning.
178145

179146
Later, once all the backing indices have finished, the [reindex status API](https://www.elastic.co/docs/api/doc/elasticsearch/operation/operation-indices-get-migrate-reindex-status) will return something like the following:
180147

@@ -226,7 +193,7 @@ which returns:
226193
}
227194
```
228195

229-
Index `.ds-my-data-stream-2025.01.23-000004` is the write index and didnt need to be upgraded because it was created with version 8.x. The other three backing indices are now prefixed with `.migrated` because they have been upgraded.
196+
Index `.ds-my-data-stream-2025.01.23-000004` is the write index and didn't need to be upgraded because it was created with version 8.x. The other three backing indices are now prefixed with `.migrated` because they have been upgraded.
230197

231198
We can now check the indices and verify that they have version 8.x:
232199

@@ -250,8 +217,7 @@ which returns:
250217
}
251218
```
252219

253-
254-
### Handling Failures [reindex-data-stream-handling-failure]
220+
### Handling failures [reindex-data-stream-handling-failure]
255221

256222
Since the reindex data stream API runs in the background, failure information can be obtained through the [reindex status API](https://www.elastic.co/docs/api/doc/elasticsearch/operation/operation-indices-get-migrate-reindex-status). For example, if the backing index `.ds-my-data-stream-2025.01.23-000002` was accidentally deleted by a user, we would see a status like the following:
257223

@@ -273,4 +239,4 @@ Since the reindex data stream API runs in the background, failure information ca
273239
}
274240
```
275241

276-
Once the issue has been fixed, the failed reindex task can be re-run. First, the failed runs status must be cleared using the [reindex cancel API](https://www.elastic.co/docs/api/doc/elasticsearch/operation/operation-indices-cancel-migrate-reindex). Then the [original reindex command](#reindex-data-stream-start) can be called to pick up where it left off.
242+
Once the issue has been fixed, the failed reindex task can be re-run. First, the failed run's status must be cleared using the [reindex cancel API](https://www.elastic.co/docs/api/doc/elasticsearch/operation/operation-indices-cancel-migrate-reindex). Then the original reindex command can be called to pick up where it left off.

0 commit comments

Comments
 (0)