elasticsearch-datastream总结

一,什么是datastream

datastream是为了更方便的管理时序数据的生命周期而基于ilm扩展的特殊功能。

二,datastream的特点

  • 1,文档必须有@timestamp字段
  • 2,定义ilm时无需定义iml别名
  • 3,可以对datastream进行插入和查询文档,但不能删除和更新文档
  • 4,datastream像别名一样管理多个真实索引(隐藏在dataStream背后),这种索引的名称规则:
.ds-datastream名称-yyyy.MM.dd-六位序列号


如下(假设datastream名称是test-data-stream):

.ds-test-data-stream-2022.05.09-000001

三,使用步骤

1,定义ilm

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": {}
        }
      }
    }
  }
}

2,定义mapping和setting

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"
  }
}

3,设置刷新时间为1s,方便测试

PUT _cluster/settings
{
  "transient": {
    "indices.lifecycle.poll_interval": "1s"
  }
}

4,定义索引模板


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"
  }
}

5,插入数据,生成dataStream索引(隐式生成,系统会根据模板中的data_stream标志自动删除dataStream)

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" }

6,验证结果


GET test-data-stream/_ilm/explain

GET test-data-stream/_search
GET .ds-test-data-stream-2022.05.09-000001/_search
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

小手追梦

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值