Elasticsearch Data streams数据流实操

  • 现有以下文档,请编写一个名为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"""
        }
      }
    ]
  }
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值