Elasticsearch 别名使用 API、别名使用场景及索引最佳实践

本贴最后更新于 2330 天前,其中的信息可能已经时过境迁

索引别名相关 API

创建别名

将别名 alias1 与索引 test1 相关联的示例:

POST /_aliases
{
    "actions" : [
        { "add" : { "index" : "test1", "alias" : "alias1" } }
    ]
}

删除别名

POST /_aliases
{
    "actions" : [
        { "remove" : { "index" : "test1", "alias" : "alias1" } }
    ]
}

重命名别名

重命名一个别名是一个简单的删除,然后在同一个 API 中添加操作。 这个操作是原子的,不用担心别名不指向索引的短时间:

POST /_aliases
{
    "actions" : [
        { "remove" : { "index" : "test1", "alias" : "alias1" } },
        { "add" : { "index" : "test2", "alias" : "alias1" } }
    ]
}

别名与多索引关联

将一个别名与多个索引关联起来只需要几个添加操作:

POST /_aliases
{
    "actions" : [
        { "add" : { "index" : "test1", "alias" : "alias1" } },
        { "add" : { "index" : "test2", "alias" : "alias1" } }
    ]
}

或者

POST /_aliases
{
    "actions" : [
        { "add" : { "indices" : ["test1", "test2"], "alias" : "alias1" } }
    ]
}

问题来了: 通过别名 alias1 访问索引,那到底是哪个索引呢????

关于别名其他操作, 参考详细 API: https://www.elastic.co/guide/en/elasticsearch/reference/5.5/indices-aliases.html

别名使用场景

索引别名和零停机时间

参考文章为: https://es.xiaoleilu.com/070_Index_Mgmt/55_Aliases.html

索引最佳实践

创建索引时, 暴露给使用方的总是别名名称,方便当索引结构发生变化时,方便 零停机 切换

  • Elasticsearch

    Elasticsearch 是一个基于 Lucene 的搜索服务器。它提供了一个分布式多用户能力的全文搜索引擎,基于 RESTful 接口。Elasticsearch 是用 Java 开发的,并作为 Apache 许可条款下的开放源码发布,是当前流行的企业级搜索引擎。设计用于云计算中,能够达到实时搜索,稳定,可靠,快速,安装使用方便。

    116 引用 • 99 回帖 • 267 关注

相关帖子

欢迎来到这里!

我们正在构建一个小众社区,大家在这里相互信任,以平等 • 自由 • 奔放的价值观进行分享交流。最终,希望大家能够找到与自己志同道合的伙伴,共同成长。

注册 关于
请输入回帖内容 ...