datastream是为了更方便的管理时序数据的生命周期而基于ilm扩展的特殊功能。
.ds-datastream名称-yyyy.MM.dd-六位序列号
如下(假设datastream名称是test-data-stream
):
.ds-test-data-stream-2022.05.09-000001
PUT _ilm/policy/my-lifecycle-policy
{
"policy": {
"phases": {
"hot": {
"min_age": "0ms",
"actions": {
"rollover": {
"max_primary_shard_size": "50gb",
"max_docs": 3,
"max_age": "7d",
"max_size": "5gb"
}
}
},
"warm": {
"min_age": "30s",
"actions": {
"shrink": {
"number_of_shards": 1
},
"forcemerge": {
"max_num_segments": 1
},
"allocate": {
"number_of_replicas": 0
}
}
},
"cold": {
"min_age": "60s",
"actions": {
"freeze" : { }
}
},
"delete": {
"min_age": "735d",
"actions": {
"delete": {}
}
}
}
}
}
PUT _component_template/my-mappings
{
"template": {
"mappings": {
"properties": {
"@timestamp": {
"type": "date",
"format": "date_optional_time||epoch_millis"
},
"message": {
"type": "wildcard"
}
}
}
},
"_meta": {
"description": "Mappings for @timestamp and message fields",
"my-custom-meta-field": "More arbitrary metadata"
}
}
# Creates a component template for index settings
PUT _component_template/my-settings
{
"template": {
"settings": {
"index.lifecycle.name": "my-lifecycle-policy"
}
},
"_meta": {
"description": "Settings for ILM",
"my-custom-meta-field": "More arbitrary metadata"
}
}
PUT _cluster/settings
{
"transient": {
"indices.lifecycle.poll_interval": "1s"
}
}
PUT _index_template/my-index-template
{
"index_patterns": ["test-data-stream*"],
"data_stream": { },
"composed_of": [ "my-mappings", "my-settings" ],
"priority": 500,
"_meta": {
"description": "Template for my time series data",
"my-custom-meta-field": "More arbitrary metadata"
}
}
PUT test-data-stream/_bulk
{ "create":{ } }
{ "@timestamp": "2099-03-08T11:04:05.000Z","message": "test" }
PUT test-data-stream/_bulk
{ "create":{ } }
{ "@timestamp": "2099-03-08T11:04:05.000Z","message": "test" }
PUT test-data-stream/_bulk
{ "create":{ } }
{ "@timestamp": "2099-03-08T11:04:05.000Z","message": "test" }
PUT test-data-stream/_bulk
{ "create":{ } }
{ "@timestamp": "2099-03-08T11:04:05.000Z","message": "test" }
GET test-data-stream/_ilm/explain
GET test-data-stream/_search
GET .ds-test-data-stream-2022.05.09-000001/_search
因篇幅问题不能全部显示,请点此查看更多更全内容