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

OpenSearch使用ISM策略执行Shrink后,原索引是否应自动删除?

OpenSearch ISM Shrink操作后原索引未自动删除的问题

我为索引配置了ISM策略,该策略会将索引在不同状态间迁移。在策略的最后一个cold状态执行分片Shrink操作后,我预期原索引会被删除,但仍能看到原索引存在。

执行GET http://localhost:9200/_cat/indices请求得到如下结果:

HTTP/1.1 200 OK
content-type: text/plain; charset=UTF-8

green open businesslog-longterm-000001_shrunken m6nVneoYSRyoPxulpN6Hkg 2 1 725   0   815kb 407.5kb
green open businesslog-longterm-000001          3Ns6iCjuQJySHMC-o63atw 4 1 725   0 816.3kb 408.1kb

请问OpenSearch在执行Shrink操作后是否应该自动删除原索引?

测试集群的ISM策略配置如下:

PUT http://localhost:9200/_plugins/_ism/policies/businesslog-longterm-policy
Content-Type: application/json

{
  "policy": {
    "description": "BusinessLog LONG-TERM policy",
    "default_state": "hot",
    "states": [
      {
        "name": "hot",
        "actions": [
          {
            "rollover": {
              "min_doc_count": "200"
            },
            "retry": {
              "count": 3,
              "backoff": "exponential",
              "delay": "1m"
            }
          },
          {
            "index_priority": {
              "priority": 100
            }
          }
        ],
        "transitions": [
          {
            "state_name": "warm",
            "conditions": {
              "min_rollover_age": "15m"
            }
          }
        ]
      },
      {
        "name": "warm",
        "actions": [
          {
            "force_merge": {
              "max_num_segments": 1
            },
            "retry": {
              "count": 3,
              "backoff": "exponential",
              "delay": "1m"
            }
          },
          {
            "index_priority": {
              "priority": 50
            }
          }
        ],
        "transitions": [
          {
            "state_name": "cold",
            "conditions": {
              "min_rollover_age": "10m"
            }
          }
        ]
      },
      {
        "name": "cold",
        "actions": [
          {
            "shrink": {
              "num_new_shards": 2,
              "target_index_name_template": {
                "source": "{{ctx.index}}_shrunken",
                "lang": "mustache"
              },
              "force_unsafe": true
            }
          },
          {
            "index_priority": {
              "priority": 0
            }
          }
        ],
        "transitions": [
        ]
      }
    ],
    "ism_template": {
      "index_patterns": ["businesslog-longterm*"],
      "priority": 100
    }
  }
}

解答

OpenSearch的ISM Shrink操作不会自动删除原索引,这是默认行为。你的策略仅配置了Shrink动作来生成收缩后的新索引,没有添加删除原索引的步骤,因此原索引会被保留。

如果需要在Shrink完成后自动删除原索引,需要在cold状态的actions列表中添加delete动作,且要放在Shrink动作之后(确保收缩操作完成后再执行删除)。修改后的cold状态配置如下:

{
  "name": "cold",
  "actions": [
    {
      "shrink": {
        "num_new_shards": 2,
        "target_index_name_template": {
          "source": "{{ctx.index}}_shrunken",
          "lang": "mustache"
        },
        "force_unsafe": true
      }
    },
    {
      "delete": {}
    },
    {
      "index_priority": {
        "priority": 0
      }
    }
  ],
  "transitions": []
}

添加delete动作后,ISM会按顺序执行:先完成Shrink操作,再删除原索引。你可以通过执行GET _plugins/_ism/status/businesslog-longterm-000001查看策略的执行状态,确认Shrink操作已成功完成后,再验证原索引是否被删除。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.16 03:23:23