📣 极限科技诚招搜索运维工程师(Elasticsearch/Easysearch)- 全职/北京 👉 : 立即申请加入

配置项作用 #

index_state_management.history.max_age 配置项用于控制ISM 历史索引触发滚动操作前的最大存活时间

当历史索引的年龄达到此配置值时,系统会自动创建新的历史索引并将写入别名指向新索引。

配置项属性 #

  • 配置路径: index_state_management.history.max_age
  • 数据类型: TimeValue(时间值)
  • 默认值: 24h(24小时)
  • 是否可选: 是
  • 作用域: NodeScope(节点级别)
  • 动态更新: 是(支持动态更新)

配置项详解 #

工作机制 #

历史索引滚动流程

历史索引创建 (.ism-history-000001)
    │
    ↓
记录 ISM 操作历史
    │
    ↓
定期检查年龄 (rollover_check_period)
    │
    ├──────── 年龄 < max_age ──→ 继续使用 ✅
    │
    └──────── 年龄 ≥ max_age ──→ 触发滚动
                                │
                                ↓
                           创建新历史索引
                           (.ism-history-000002)
                                │
                                ↓
                           更新别名指向
                                │
                                ↓
                           旧索引只读

年龄计算 #

索引年龄计算方式

创建时间:
2024-01-01 10:00:00


当前时间:
2024-01-02 10:00:00


索引年龄:
= 当前时间 - 创建时间
= 24小时


max_age = 24h:
年龄 = 24h ≥ max_age = 24h
    ↓
触发滚动 ✅


max_age = 12h:
年龄 = 24h ≥ max_age = 12h
    ↓
早已触发滚动 ✅

滚动检查周期 #

检查周期与滚动

rollover_check_period = 8h
max_age = 24h

时间线:
0h ────→ 8h ────→ 16h ────→ 24h ────→ 32h
│        │         │          │          │
创建    检查(8h)  检查(16h)  检查(24h)  检查(32h)
                    ↓          ↓          ↓
                   未达到     达到✅     滚动已执行

实际滚动时间可能在 24h-32h 之间
取决于检查周期

配置建议 #

生产环境(默认) #

index_state_management:
  history:
    max_age: 24h  # 默认值

建议: 保持默认值 24h。适用于大多数场景。

大量历史记录 #

index_state_management:
  history:
    max_age: 12h  # 12 小时

建议: 减少到 6-12h。ISM 操作非常频繁时使用。

长期审计需求 #

index_state_management:
  history:
    max_age: 7d  # 7 天

建议: 增加到 3-7d。需要更长的单索引历史时使用。

测试环境 #

index_state_management:
  history:
    max_age: 1h  # 1 小时

建议: 设置为 1-4h。测试环境使用。

代码示例 #

easysearch.yml 基础配置 #

index_state_management:
  history:
    max_age: 24h

配合其他历史配置 #

index_state_management:
  history:
    enabled: true
    max_age: 24h
    max_docs: 2500000
    rollover_check_period: 8h

快速滚动配置 #

index_state_management:
  history:
    max_age: 6h
    rollover_check_period: 2h

动态更新配置 #

PUT /_cluster/settings
{
  "transient": {
    "index_state_management.history.max_age": "12h"
  }
}

相关配置 #

配置项作用默认值
index_state_management.history.enabled是否启用历史记录true
index_state_management.history.max_age历史索引最大年龄24h
index_state_management.history.max_docs历史索引最大文档数2500000
index_state_management.history.rollover_check_period滚动检查周期8h
index_state_management.history.rollover_retention_period历史索引保留期30d

滚动条件组合 #

双条件滚动机制

历史索引会在以下任一条件满足时滚动:

条件 1: max_age
索引年龄 ≥ 24小时
    ↓
触发滚动

条件 2: max_docs
文档数 ≥ 2500000
    ↓
触发滚动

先达到条件的优先触发滚动

使用场景 #

推荐使用默认值的场景 #

  • 标准生产: 正常的 ISM 操作频率
  • 中等规模: 托管索引数量适中
  • 平衡需求: 平衡索引大小和数量

推荐减少 max_age 的场景 #

  • 高频操作: ISM 策略执行非常频繁
  • 快速检索: 希望单个索引较小
  • 存储优化: 优化查询和存储性能

推荐增加 max_age 的场景 #

  • 低频操作: ISM 操作不频繁
  • 简化管理: 减少索引数量
  • 长期审计: 需要更长时间的历史集中

索引命名模式 #

历史索引命名规则

.ism-history-000001  (创建: 2024-01-01 10:00)
.ism-history-000002  (创建: 2024-01-02 10:00) ← 24h 后滚动
.ism-history-000003  (创建: 2024-01-03 10:00) ← 再过 24h 滚动
.ism-history-000004  (创建: 2024-01-04 10:00)

别名始终指向最新索引:
.ism-history → .ism-history-000004

存储估算 #

基于 max_age 的存储估算

假设:
- 每小时 1000 条 ISM 操作
- 每条记录 10KB

max_age = 24h:
单索引大小 ≈ 1000 × 24 × 10KB ≈ 240MB

max_age = 12h:
单索引大小 ≈ 1000 × 12 × 10KB ≈ 120MB

max_age = 7d:
单索引大小 ≈ 1000 × 168 × 10KB ≈ 1.68GB

配合保留期 (rollover_retention_period = 30d):
max_age = 24h 时约 30 个索引
总存储 ≈ 240MB × 30 ≈ 7.2GB

注意事项 #

  1. 时间单位: 支持多种时间单位(ms, s, m, h, d)。

  2. 检查周期: 实际滚动时间取决于 rollover_check_period

  3. 与 max_docs 配合: 两个条件任一满足都会触发滚动。

  4. 动态更新: 支持动态更新,修改后立即生效。

  5. 保留期设置: 确保 rollover_retention_period 足够大。

  6. 存储规划: 根据操作频率合理规划存储空间。

  7. 查询影响: 更多索引可能影响查询性能。

  8. 备份策略: 滚动产生的旧索引需要包含在备份中。

  9. 监控建议: 监控历史索引的数量和总大小。

  10. 版本兼容: 新旧版本的默认值可能不同。