You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何在Elasticsearch中创建两个别名:一个在Hot Tier,一个在其他存储层级

Elasticsearch 按存储层级拆分索引别名实现方案

1. 创建指向Hot Tier索引的别名

利用Elasticsearch的别名API,通过索引自带的_tier元字段匹配Hot层索引(该字段由ES自动生成,对应索引所在的存储层级):

PUT /_alias/hot_data
{
  "filter": {
    "term": {
      "_tier": "data_hot"
    }
  },
  "index_patterns": ["your-index-prefix-*"]
}
  • 替换your-index-prefix-*为你的实际索引前缀,确保仅匹配目标索引集合。
  • 如果你的索引是通过自定义元数据标记层级(比如index.metadata.tier: hot),可改用_index_metadata.tier字段过滤。

2. 创建指向Warm/Cold等非Hot层级的别名

通过must_not排除Hot层索引,将其余层级的索引关联到同一个别名:

PUT /_alias/archived_data
{
  "filter": {
    "bool": {
      "must_not": {
        "term": {
          "_tier": "data_hot"
        }
      }
    }
  },
  "index_patterns": ["your-index-prefix-*"]
}

该别名会自动包含Warm、Cold、Frozen等所有非Hot层级的索引。

3. 验证别名配置

检查别名关联的索引列表:

GET /_alias/hot_data
GET /_alias/archived_data

也可以通过搜索测试效果:

GET /hot_data/_search?q=*
GET /archived_data/_search?q=*

4. 结合ILM自动维护别名(可选)

如果使用索引生命周期管理(ILM),可以在策略中配置索引流转时自动更新别名,无需手动维护:

PUT /_ilm/policy/your-tier-policy
{
  "policy": {
    "phases": {
      "hot": {
        "actions": {
          "add": {
            "aliases": ["hot_data"]
          }
        }
      },
      "warm": {
        "actions": {
          "remove": {
            "aliases": ["hot_data"]
          },
          "add": {
            "aliases": ["archived_data"]
          }
        }
      },
      "cold": {
        "actions": {
          "add": {
            "aliases": ["archived_data"]
          }
        }
      }
    }
  }
}

将该策略绑定到索引模板后,索引在Hot→Warm→Cold的流转过程中会自动加入/移除对应别名。

内容的提问来源于stack exchange,提问作者Imlucky

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.25 22:57:25