Reindex a time series data stream
Serverless Stack
Reindexing allows you to copy documents from an existing time series data stream (TSDS) to a new one. All data streams support reindexing, but time series data streams require special handling due to their time-bound backing indices and strict timestamp acceptance windows.
When you reindex, the result is a single backing index of a new data stream.
To reindex, follow the steps on this page.
This process only applies to time series data streams without a downsampling configuration. To reindex a downsampled data stream, reindex the backing indices individually, then add them to a new, empty data stream.
These high-level steps summarize the process of reindexing a time series data stream. Each step is detailed in a later section.
- Create an index template for the destination data stream
- Update the template with temporary settings for reindexing
- Run the reindex operation
- Revert the temporary index settings
- Perform a manual rollover to create a new backing index for incoming data
The examples on this page use Dev Tools Console syntax.
Create an index template for the new TSDS, using your preferred mappings and settings:
PUT _index_template/my-new-tsds-template
{
"index_patterns": ["my-new-tsds"],
"priority": 100,
"data_stream": {},
"template": {
"settings": {
"index.mode": "time_series"
},
"mappings": {
"properties": {
"@timestamp": {
"type": "date"
},
"dimension_field": {
"type": "keyword",
"time_series_dimension": true
},
"metric_field": {
"type": "double",
"time_series_metric": "gauge"
}
}
}
}
}
To support the reindexing process, you need to temporarily modify the template:
- Set
index.time_series.start_timeandindex.time_series.end_timeindex settings to match the lowest and highest@timestampvalues in the old data stream. - Set
index.number_of_shardsto the sum of all primary shards of all backing indices of the old data stream. - Clear the
index.lifecycle.nameindex setting (if any), to prevent ILM from modifying the destination data stream during reindexing. - (Optional) Set
index.number_of_replicasto zero, to speed up reindexing. Because the data gets copied in the reindexing process, you don't need replicas.
PUT _index_template/new-tsds-template
{
"index_patterns": ["new-tsds*"],
"priority": 100,
"data_stream": {},
"template": {
"settings": {
"index.mode": "time_series",
"index.routing_path": ["host", "service"],
"index.time_series.start_time": "2023-01-01T00:00:00Z",
"index.time_series.end_time": "2025-01-01T00:00:00Z",
"index.number_of_shards": 6,
"index.number_of_replicas": 0,
"index.lifecycle.name": null
},
"mappings": {
...
}
}
}
- Lowest timestamp value in the old data stream
- Highest timestamp value in the old data stream
- Sum of the primary shards from all source backing indices
- Speed up reindexing
- Pause ILM
Run the reindex operation:
POST /_reindex
{
"source": {
"index": "old-tsds"
},
"dest": {
"index": "new-tsds",
"op_type": "create"
}
}
After reindexing completes, update the index template again to remove the temporary settings:
- Remove the overrides for
index.time_series.start_timeandindex.time_series.end_time. - Restore the values of
index.number_of_shards,index.number_of_replicas, andindex.lifecycle.name(as applicable).
PUT _index_template/new-tsds-template
{
"index_patterns": ["new-tsds*"],
"priority": 100,
"data_stream": {},
"template": {
"settings": {
"index.mode": "time_series",
"index.routing_path": ["host", "service"],
"index.number_of_replicas": 1,
"index.lifecycle.name": "my-ilm-policy"
},
"mappings": {
...
}
}
}
- Restore replicas
- Re-enable ILM
Create a new backing index with a manual rollover request:
POST new-tsds/_rollover/
The destination data stream is now ready to accept new documents.