- 现有以下文档,请编写一个名为test_data_stream数据流满足以下请求:
{
"@timestamp": "2099-03-08T11:04:05.000Z",
"message": "test"
}
- 数据流索引的主分片数为3,副本分片数为1
- 将上述文档填充到数据流中去
基于ES7.13版本
#创建索引生命周期管理来管理数据流索引
PUT _ilm/policy/data_stream_ilm
{
"policy": {
"phases": {
"hot": {
"actions": {
"set_priority": {
"priority": 100
},
"rollover": {
"max_age": "7d",
"max_docs": 1000,
"max_size": "5gb"
}
}
},
"warm": {
"min_age": "1d",
"actions": {
"set_priority": {
"priority": 50
},
"allocate": {
"number_of_replicas": 0
},
"shrink": {
"number_of_shards": 1
},
"forcemerge": {
"max_num_segments": 1
}
}
},
"cold": {
"min_age": "1d",
"actions": {
"set_priority": {
"priority": 0
},
"freeze": {}
}
},
"delete": {
"min_age": "1d",
"actions": {
"delete": {}
}
}
}
}
}
#创建索引组件模板
PUT _component_template/settings
{
"template": {
"settings": {
"index.lifecycle.name":"data_stream_ilm",
"number_of_shards": 3,
"number_of_replicas": 1
}
}
}
PUT _component_template/mappings
{
"template": {
"mappings": {
"properties": {
"@timestamp":{
"type": "date",
"format": "date_optional_time||epoch_millis"
}
}
}
}
}
#创建索引模板
PUT _index_template/data_stream_template
{
"data_stream":{},
"composed_of":["settings","mappings"],
"index_patterns": ["test_data_stream*"]
}
#创建数据流
PUT _data_stream/test_data_stream
#索引文档
POST test_data_stream/_doc
{
"@timestamp": "2099-03-08T11:04:05.000Z",
"message": "test"
}
#搜索验证写入索引
GET .ds-my-data-stream-2021.10.22*/_search
响应:
{
"took" : 1,
"timed_out" : false,
"_shards" : {
"total" : 9,
"successful" : 9,
"skipped" : 0,
"failed" : 0
},
"hits" : {
"total" : {
"value" : 7,
"relation" : "eq"
},
"max_score" : 1.0,
"hits" : [
{
"_index" : ".ds-my-data-stream-2021.10.22-000001",
"_type" : "_doc",
"_id" : "96Uwp3wBBZpCAsOBCuLE",
"_score" : 1.0,
"_source" : {
"@timestamp" : "2099-05-06T16:21:15.000Z",
"message" : """192.0.2.42 - - [06/May/2099:16:21:15 +0000] "GET /images/bg.jpg HTTP/1.0" 200 24736"""
}
},
{
"_index" : ".ds-my-data-stream-2021.10.22-000002",
"_type" : "_doc",
"_id" : "CKU3p3wBBZpCAsOBJeMK",
"_score" : 1.0,
"_source" : {
"@timestamp" : "2099-05-06T16:21:56.000Z",
"message" : """192.0.2.42 - - [06/May/2099:16:21:15 +0000] "GET /images/bg.jpg HTTP/1.0" 200 24736"""
}
},
{
"_index" : ".ds-my-data-stream-2021.10.22-000001",
"_type" : "_doc",
"_id" : "9qUvp3wBBZpCAsOB--Ik",
"_score" : 1.0,
"_source" : {
"@timestamp" : "2099-05-06T16:25:42.000Z",
"message" : """192.0.2.255 - - [06/May/2099:16:25:42 +0000] "GET /favicon.ico HTTP/1.0" 200 3638"""
}
},
{
"_index" : ".ds-my-data-stream-2021.10.22-000002",
"_type" : "_doc",
"_id" : "BaU1p3wBBZpCAsOB8OOF",
"_score" : 1.0,
"_source" : {
"@timestamp" : "2099-05-06T16:25:44.000Z",
"message" : """192.0.2.255 - - [06/May/2099:16:25:42 +0000] "GET /favicon.ico HTTP/1.0" 200 3638"""
}
},
{
"_index" : ".ds-my-data-stream-2021.10.22-000002",
"_type" : "_doc",
"_id" : "CaU3p3wBBZpCAsOBJeMK",
"_score" : 1.0,
"_source" : {
"@timestamp" : "2099-05-06T16:25:57.000Z",
"message" : """192.0.2.255 - - [06/May/2099:16:25:42 +0000] "GET /favicon.ico HTTP/1.0" 200 3638"""
}
},
{
"_index" : ".ds-my-data-stream-2021.10.22-000001",
"_type" : "_doc",
"_id" : "9aUvp3wBBZpCAsOB--Ik",
"_score" : 1.0,
"_source" : {
"@timestamp" : "2099-05-06T16:21:15.000Z",
"message" : """192.0.2.42 - - [06/May/2099:16:21:15 +0000] "GET /images/bg.jpg HTTP/1.0" 200 24736"""
}
},
{
"_index" : ".ds-my-data-stream-2021.10.22-000002",
"_type" : "_doc",
"_id" : "BKU1p3wBBZpCAsOB8OOF",
"_score" : 1.0,
"_source" : {
"@timestamp" : "2099-05-06T16:21:34.000Z",
"message" : """192.0.2.42 - - [06/May/2099:16:21:15 +0000] "GET /images/bg.jpg HTTP/1.0" 200 24736"""
}
}
]
}
}