加载中

从汇总迁移到 Elasticsearch 中的降采样

了解如何从传统的汇总作业过渡到 Elasticsearch 降采样。本文档介绍了两者之间的主要区别,并概述了迁移步骤。

降采样的以下方面比使用汇总作业更简单或更健壮:

  • 无需调度作业。降采样与索引生命周期管理 (ILM) 和数据流生命周期 (DSL) 集成在一起。
  • 无需单独的搜索 API。可以使用搜索 API 和 ES|QL 访问降采样索引。
  • 无需单独的汇总配置。降采样使用映射中的时间序列维度和指标配置。

并非所有汇总用法都可以迁移到降采样。主要要求是数据必须以时间序列数据流 (TSDS) 的形式存储在 Elasticsearch 中。基本上按时间和所有维度汇总数据的汇总用法可以迁移到降采样。

一个可以迁移到降采样的汇总用法示例

				PUT _rollup/job/sensor
					{
  "index_pattern": "sensor-*",
  "rollup_index": "sensor_rollup",
  "cron": "0 0 * * * *",
  "page_size": 1000,
  "groups": {
    "date_histogram": {
      "field": "timestamp",
      "fixed_interval": "60m"
    },
    "terms": {
      "fields": [ "node" ]
    }
  },
  "metrics": [
    {
      "field": "temperature",
      "metrics": [ "min", "max", "sum" ]
    },
    {
      "field": "voltage",
      "metrics": [ "avg" ]
    }
  ]
}
		

使用 DSL 进行降采样的等效时间序列数据流 (TSDS) 设置

				PUT _index_template/sensor-template
					{
  "index_patterns": ["sensor-*"],
  "data_stream": { },
  "template": {
    "lifecycle": {
        "downsampling": [
            {
                "after": "1d",
                "fixed_interval": "1h"
            }
        ]
    },
    "settings": {
      "index.mode": "time_series"
    },
    "mappings": {
      "properties": {
        "node": {
          "type": "keyword",
          "time_series_dimension": true
        },
        "temperature": {
          "type": "half_float",
          "time_series_metric": "gauge"
        },
        "voltage": {
          "type": "half_float",
          "time_series_metric": "gauge"
        },
        "@timestamp": {
          "type": "date"
        }
      }
    }
  }
}
		

上述时间序列数据流 (TSDS) 模板中包含了降采样配置。只需 downsampling 部分即可启用降采样,该部分指明了何时降采样以及降采样到什么固定间隔。

  1. 在汇总作业中,cron 字段决定了何时对文档进行汇总。在索引模板中,after 字段决定了何时进行降采样汇总文档(这是执行滚动更新之后的时间)。
  2. 在汇总作业中,groups 字段决定了分组文档汇总到的所有维度。在索引模板中,将 time_series_dimension 设置为 true 的字段和 @timestamp 字段决定了分组。
  3. 在汇总作业中,fixed_interval 字段决定了如何将时间戳作为分组的一部分进行聚合。在索引模板中,fixed_interval 字段具有相同的作用。降采样不支持日历间隔。
  4. 在汇总作业中,metrics 字段定义了指标以及如何存储这些指标。在索引模板中,所有具有 time_series_metric 的字段均为指标字段。如果一个字段将 gauge 作为 time_series_metric 属性值,则该字段的最小值、最大值、总和和值计数将存储在降采样索引中。如果一个字段将 counter 作为 time_series_metric 属性值,则该字段仅最后存储的值会保存在降采样索引中。
© . This website operates independently and is not affiliated with or endorsed by Elasticsearch B.V. All brand names, logos, and trademarks are the property of their respective owners.