基于阶段 Elasticsearch 在索引翻转上添加别名

Adding aliases on index roll over based on phase Elasticsearch

我有以下电影(忽略最低年龄,用于测试):

"somerandomilm": {
    "version": 3,
    "modified_date": "2020-04-09T16:09:16.952Z",
    "policy": {
        "phases": {
            "warm": {
                "min_age": "3m",
                "actions": {
                    "allocate": {
                        "include": {
                            "phase_id": "warm"
                        },
                        "exclude": {},
                        "require": {}
                    },
                    "shrink": {
                        "number_of_shards": 1
                    },
                    "forcemerge": {
                        "max_num_segments": 1
                    },
                    "set_priority": {
                        "priority": 25
                    }
                }
            },
            "cold": {
                "min_age": "5m",
                "actions": {
                    "allocate": {
                        "include": {
                            "phase_id": "cold"
                        },
                        "exclude": {},
                        "require": {}
                    },
                    "set_priority": {
                        "priority": 25
                    }
                }
            },
            "hot": {
                "min_age": "0ms",
                "actions": {
                    "rollover": {
                        "max_size": "30gb",
                        "max_age": "3m"
                    },
                    "set_priority": {
                        "priority": 50
                    }
                }
            }
        }
    }
}

和第一个起始索引:

"somerandomindexname-000001": {
    "aliases": {
        "genericrolloveralias": {
            "is_write_index": false
        }
    },
    "mappings": {
        "properties": {
            "Id": {
                "type": "text"
            },
            "SomeOtherProperty": {
                "type": "text"
            },
            "SomeOtherProperty2": {
                "type": "text"
            }
        }
    },
    "settings": {
        "index": {
            "lifecycle": {
                "name": "somerandomilm",
                "rollover_alias": "genericrolloveralias",
                "indexing_complete": "true"
            },
            "routing": {
                "allocation": {
                    "include": {
                        "phase_id": "warm"
                    }
                }
            },
            "number_of_shards": "1",
            "provided_name": "somerandomindexname-000001",
            "creation_date": "1586447619447",
            "priority": "25",
            "number_of_replicas": "1",
            "uuid": "ByKhH8dnR_Sx50GwWNjJaQ",
            "version": {
                "created": "7060099"
            }
        }
    }
}

模板:

    "randomtemplate_template": {
    "order": 0,
    "index_patterns": [
        "somerandomindexname-*"
    ],
    "settings": {
        "index": {
            "lifecycle": {
                "name": "somerandomilm",
                "rollover_alias": "genericrolloveralias"
            },
            "number_of_shards": "1",
            "number_of_replicas": "1"
        }
    },
    "mappings": {},
    "aliases": {}
},

是否可以弹性地根据当前移动到的阶段为索引添加额外的别名?

即:当索引移至暖索引时,所有处于暖索引中的索引是否都可以添加一个额外的别名来指示它处于哪个阶段?我的最终目标是能够查询像 hot/warm 这样的特定节点,我的理解是这可以通过别名实现。

通过调用 ILM explain api 解决了这个问题,它提供了索引列表及其当前阶段。一旦我有了列表,我就可以过滤掉任何已经移动或正在移动到暖阶段的索引和 运行 批量别名操作。

var resp = _client.IndexLifecycleManagement.ExplainLifecycleAsync(new ExplainLifecycleRequest(_hotIndexAlias));

var warmPhaseIndices = resp .Indices.Where(i => i.Value.Phase == "warm").ToList();