0Pricing
Elasticsearch & Full Text Search Systems · 课时

时间序列数据管理

针对时间序列数据优化 Elasticsearch,包括数据流、ILM(索引生命周期管理)以及冷热数据架构。

时间序列数据管理 是 CoddyKit 上的免费 Elasticsearch & Full Text Search Systems 课时。 这是第 2 节课,共 4 节。 你可以在下方免费阅读本课时的完整内容 — 然后在浏览器中使用内置代码编辑器和全天候 AI 导师进行实践。 这是 Elasticsearch & Full Text Search Systems 学习路径的一部分,你的进度在网页和 CoddyKit 应用中同步。 Elasticsearch & Full Text Search Systems 课程共包含 4 节课。

本课时的部分内容尚未翻译,以英文显示。

What is Time-Series Data?

Time-series data is information collected over a period of time, often at regular intervals. Think of it as a sequence of data points indexed by time.

Examples include:

  • System logs: Events happening on a server.
  • IoT sensor readings: Temperature, humidity from devices.
  • Financial data: Stock prices over days or hours.

This data is typically append-only and usually immutable once recorded.

Why Elasticsearch for Time-Series?

Elasticsearch is an excellent choice for managing time-series data due to its:

  • Scalability: Handles massive volumes of data.
  • Speed: Fast indexing and search capabilities.
  • Analytics: Powerful aggregations for insights.
  • Flexibility: Can store structured and unstructured data.

It's particularly strong for use cases like log analytics, metric monitoring, and security event management.

Introducing Data Streams

Data streams are a core feature in Elasticsearch designed specifically for time-series data. They simplify management by automatically rolling over to new indices as needed.

When you index data into a data stream, it always writes to the current write index. Queries, however, search across all backing indices transparently. This makes managing large, continuously growing datasets much easier.

Creating Your First Data Stream

To create a data stream, you first need an index template that defines its structure and points to a data stream.

Then, simply indexing a document into the stream's name will create it automatically based on the template:

PUT _index_template/my-data-stream-template
{
  "index_patterns": ["my-data-stream-*"],
  "data_stream": {},
  "priority": 200,
  "template": {
    "settings": {
      "number_of_shards": 1
    },
    "mappings": {
      "properties": {
        "@timestamp": {
          "type": "date",
          "format": "strict_date_optional_time||epoch_millis"
        },
        "message": { "type": "text" }
      }
    }
  }
}

// Indexing a document creates the stream
POST my-data-stream/_doc
{
  "@timestamp": "2023-10-27T10:00:00Z",
  "message": "Sensor reading: 25.5C"
}

Automating with ILM

Index Lifecycle Management (ILM) is a powerful feature that automates the management of your indices through various phases of their life.

For time-series data, ILM helps you:

  • Automatically roll over indices when they reach a certain size or age.
  • Move older, less frequently accessed data to cheaper storage.
  • Delete data that is no longer needed.

The Four ILM Phases

ILM policies define actions for indices across four main phases:

  • Hot: Indices are actively being written to and frequently queried. Requires fast storage.
  • Warm: Indices are no longer being written to, but are still queried. Can be read-only and potentially on slower storage.
  • Cold: Indices are rarely queried and often stored on very cheap, slow storage.
  • Delete: Indices are no longer needed and are safely removed from the cluster.

Crafting an ILM Policy

Here's an example of an ILM policy that defines rollover, forcemerge (for warm phase), and deletion stages for time-series data:

PUT _ilm/policy/my-ts-policy
{
  "policy": {
    "phases": {
      "hot": {
        "actions": {
          "rollover": {
            "max_age": "7d",
            "max_docs": 10000000,
            "max_size": "50gb"
          }
        }
      },
      "warm": {
        "min_age": "30d",
        "actions": {
          "forcemerge": {
            "max_num_segments": 1
          },
          "shrink": {
            "number_of_shards": 1
          }
        }
      },
      "cold": {
        "min_age": "90d",
        "actions": {
          "freeze": {}
        }
      },
      "delete": {
        "min_age": "180d",
        "actions": {
          "delete": {}
        }
      }
    }
  }
}

Hot-Warm-Cold Architecture

A Hot-Warm-Cold architecture optimizes resource utilization and cost for time-series data by using different types of nodes for different ILM phases.

  • Hot nodes: Use fast CPUs, SSDs for high indexing and query throughput.
  • Warm nodes: Use less powerful CPUs, HDDs (or slower SSDs) for older, read-only data.
  • Cold nodes: Use very cheap, high-capacity storage, potentially even object storage, for rarely accessed data.

Assigning Node Roles

You can configure nodes to serve specific roles (hot, warm, cold) by setting node.attr in their elasticsearch.yml configuration file.

ILM policies then use these attributes to automatically move indices to the appropriate node types as they transition through phases.

# For a hot node
node.roles: [ data ]
node.attr.data: hot

# For a warm node
node.roles: [ data ]
node.attr.data: warm

# For a cold node
node.roles: [ data ]
node.attr.data: cold

ILM & Data Stream Check

Which of the following statements about Elasticsearch's time-series features are TRUE?

Time-Series Recap

Great job! You've explored how Elasticsearch is optimized for time-series data.

We covered:

  • Data Streams: Simplifying index management and rollovers.
  • ILM (Index Lifecycle Management): Automating index transitions through hot, warm, cold, and delete phases.
  • Hot-Warm-Cold Architectures: Optimizing cluster resources and costs by assigning different node types to specific ILM phases.

These features are essential for building scalable and cost-effective time-series solutions with Elasticsearch.

常见问题解答

「时间序列数据管理」课时是免费的吗?

是的 — 「时间序列数据管理」的完整文本可在网页上免费阅读。要进行交互式练习(内置代码编辑器和全天候 AI 导师)并解锁 Elasticsearch & Full Text Search Systems 课程的其余内容,请升级到 CoddyKit PRO。 Elasticsearch & Full Text Search Systems 课程共包含 4 节课。

「时间序列数据管理」这节课中我会学到什么?

针对时间序列数据优化 Elasticsearch,包括数据流、ILM(索引生命周期管理)以及冷热数据架构。 你通过在浏览器中直接运行的动手代码来练习 Elasticsearch & Full Text Search Systems,全天候 AI 导师会在你学习这节课的过程中回答你的问题。

学习 Elasticsearch & Full Text Search Systems 需要有经验吗?

无需任何先前经验。CoddyKit 上的 Elasticsearch & Full Text Search Systems 课程适合初学者到高级学习者,你可以从这里开始或从头开始,按照自己的节奏学习。 这是第 2 节课,共 4 节。

「时间序列数据管理」课时需要多长时间?

大多数 CoddyKit 课程大约需要 5–10 分钟。每节课都很精短且互动,所以你能稳步进步,并在网页和应用中从离开的地方继续。

我能在这节 Elasticsearch & Full Text Search Systems 课中编写并运行代码吗?

能。每节 Elasticsearch & Full Text Search Systems 课都包含内置代码编辑器,你可以在浏览器中直接编写并运行真实代码,并获得即时 AI 反馈 — 无需本地设置。

此课程中的所有课时

  1. 地理空间搜索功能
  2. 时间序列数据管理
  3. 生产环境部署策略
  4. 索引生命周期管理
← 返回 Elasticsearch & Full Text Search Systems