• elasticsearch alias


    索引别名API允许使用一个名字来作为一个索引的别名,所有API会自动将别名转换为实际的索引名称。 别名也可以映射到多个索引,别名不能与索引具有相同的名称。别名可以用来做索引迁移和多个索引的查询统一,还可以用来实现视图的功能

    查看所有别名
    GET /_aliases

    查看某个别名下的索引
    GET /_alias/alias_name

    查看别名以2017开头的下的索引
    GET /_alias/2017

    查看某个索引的别名
    GET /index_name/_alias

    添加并删除别名

    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" } }
        ]
    }

    还可以使用通配符*

    POST /_aliases
    {
        "actions" : [
            { "add" : { "index" : "test*", "alias" : "all_test_indices" } }
        ]
    }

    还可以使用别名实现类似视图的功能

    PUT /test1
    {
      "mappings": {
        "type1": {
          "properties": {
            "user" : {
              "type": "keyword"
            }
          }
        }
      }
    }

    创建一个user等于kimchy的视图

    POST /_aliases
    {
        "actions" : [
            {
                "add" : {
                     "index" : "test1",
                     "alias" : "alias2",
                     "filter" : { "term" : { "user" : "kimchy" } }
                }
            }
        ]
    }

    添加单个别名

    PUT /{index}/_alias/{name}

    examples:
    PUT /logs_201305/_alias/2013

    PUT /users/_alias/user_12
    {
        "routing" : "12",
        "filter" : {
            "term" : {
                "user_id" : 12
            }
        }
    }

    创建索引时也可以指定别名

    PUT /logs_20162801
    {
        "mappings" : {
            "type" : {
                "properties" : {
                    "year" : {"type" : "integer"}
                }
            }
        },
        "aliases" : {
            "current_day" : {},
            "2016" : {
                "filter" : {
                    "term" : {"year" : 2016 }
                }
            }
        }
    }

    删除别名
    DELETE /{index}/_alias/{name}
    index * | _all | glob pattern | name1, name2, …
    name * | _all | glob pattern | name1, name2, …

    DELETE /logs_20162801/_alias/current_day

  • 相关阅读:
    python 单下划线/双下划线使用总结
    error connection reset by peer 104
    变形课
    求并联电阻值
    HDU2054:A == B ?
    Do the Untwist
    开门人和关门人
    关于HEXO安装失败的解决方法
    代码高亮显示——google-code-prettify
    网站图标——favicon
  • 原文地址:https://www.cnblogs.com/gavinYang/p/11200188.html
Copyright © 2020-2023  润新知