zoukankan      html  css  js  c++  java
  • 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

  • 相关阅读:
    OpenCV特征描述
    OpenCV特征点检测
    expect实现无交互操作
    文件的修改时间
    sshd登录攻击
    tcp三次握手和syn 洪水攻击
    vim使用
    PHP拓展开发
    【转】LINUX 手动建立SWAP文件及删除
    Ubuntu下crontab命令的用法
  • 原文地址:https://www.cnblogs.com/gavinYang/p/11200188.html
Copyright © 2011-2022 走看看