dromara / easy-es

A foolproof Elasticsearch ORM framework that is easy to use, requires minimal coding, and is highly expandable...

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

数据迁移后,新旧索引的别名切换为啥用的是默认别名?

NGU-Sunshie opened this issue · comments

如题,如果手动配置了别名,新建索引用的是配置的别名,为啥切换时候就用默认别名了?

/**
* 原子操作: 删除旧索引别名,将旧索的引别名添加至新索引
*
* @param client RestHighLevelClient
* @param oldIndexName 旧索引
* @param releaseIndexName 新索引
* @return 是否成功
*/
public static boolean changeAliasAtomic(RestHighLevelClient client, String oldIndexName, String releaseIndexName) {
IndicesAliasesRequest.AliasActions addIndexAction = new IndicesAliasesRequest.AliasActions(
IndicesAliasesRequest.AliasActions.Type.ADD).index(releaseIndexName).alias(DEFAULT_ALIAS);
IndicesAliasesRequest.AliasActions removeAction = new IndicesAliasesRequest.AliasActions(
IndicesAliasesRequest.AliasActions.Type.REMOVE).index(oldIndexName).alias(DEFAULT_ALIAS);

    IndicesAliasesRequest indicesAliasesRequest = new IndicesAliasesRequest();
    indicesAliasesRequest.addAliasAction(addIndexAction);
    indicesAliasesRequest.addAliasAction(removeAction);
    try {
        AcknowledgedResponse acknowledgedResponse = client.indices().updateAliases(indicesAliasesRequest,
                RequestOptions.DEFAULT);
        return acknowledgedResponse.isAcknowledged();
    } catch (IOException e) {
        throw ExceptionUtils.eee("changeAlias exception oldIndexName: %s, releaseIndexName: %s", e, oldIndexName, releaseIndexName);
    }
}