重索引时间序列数据流
重索引允许您将文档从现有的时间序列数据流 (TSDS) 复制到新的数据流中。所有数据流都支持重索引,但由于时间序列数据流具有时间限制的后备索引和严格的时间戳接受窗口,因此需要特殊处理。
重要提示
当您进行重索引时,结果会成为新数据流的单个后备索引。
要进行重索引,请按照本页面上的步骤操作。
注意
此过程仅适用于没有配置降采样 (downsampling) 的时间序列数据流。要重索引已降采样的数据流,请单独重索引其后备索引,然后将它们添加到一个新的空数据流中。
这些高级步骤总结了重索引时间序列数据流的过程。每个步骤都会在后续章节中详细说明。
- 为目标数据流创建索引模板
- 使用重索引的临时设置更新模板
- 运行重索引操作
- 还原临时索引设置
- 执行手动滚动以创建用于接收新数据的后备索引
本页面上的示例使用“开发工具控制台”(Console) 语法。
为新的 TSDS 创建索引模板,并使用您偏好的映射和设置
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"
}
}
}
}
}
为了支持重索引过程,您需要临时修改模板
- 将
index.time_series.start_time和index.time_series.end_time索引设置修改为与旧数据流中最低和最高@timestamp值相匹配。 - 将
index.number_of_shards设置为旧数据流所有后备索引的主分片总和。 - 清除
index.lifecycle.name索引设置(如果有),以防止 ILM 在重索引期间修改目标数据流。 - (可选) 将
index.number_of_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": {
...
}
}
}
- 旧数据流中的最低时间戳值
- 旧数据流中的最高时间戳值
- 所有源后备索引的主分片总和
- 加快重索引速度
- 暂停 ILM
运行重索引操作
POST /_reindex
{
"source": {
"index": "old-tsds"
},
"dest": {
"index": "new-tsds",
"op_type": "create"
}
}
重索引完成后,再次更新索引模板以移除临时设置
- 移除
index.time_series.start_time和index.time_series.end_time的覆盖设置。 - 还原
index.number_of_shards、index.number_of_replicas和index.lifecycle.name(如适用)的值。
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": {
...
}
}
}
- 还原副本
- 重新启用 ILM
通过手动滚动请求创建新的后备索引
POST new-tsds/_rollover/
目标数据流现在已准备好接收新文档。