zoukankan      html  css  js  c++  java
  • ES7中的alias和rollover

    个人学习笔记,谢绝转载!!!

    原文:https://www.cnblogs.com/wshenjin/p/15160383.html


    为索引设置别名后,就可以通过这个别名来操作索引,ES会自动将别名映射到实际的索引名中。

    alias的基本语法:

    给现有index添加alias:

    PUT /_alias { 
        "actions" : [ 
            {
                "add" : {
                    "index" : "students",
                    "alias" : "students_alias",
                    "is_write_index" : true
               }
            }
        ]
    }
    

    创建index并设置alias

    PUT /students {
        "settings" : {
            "number_of_shards":3 ,
            "number_of_replicas":1
        },
        "aliases" : {
          "students_alias" : {
            "is_write_index" : true
          }
        }
    }
    

    删除alias

    POST /_aliases {
        "actions" : [
            {
                "remove" : {
                     "index" : "context01",
                     "alias" : "context_alias"
                }
            },
        ]
    }
    

    关联多个索引:

    POST /_aliases {
        "actions" : [
            {
                "add" : {
                     "index" : "context01",
                     "alias" : "context_alias"
                }
            },
            {
                "add" : {
                     "index" : "context02",
                     "alias" : "context_alias",
                     "is_write_index" : true
                }
            }
        ]
    }
    

    别名不仅仅可以关联一个索引,它能聚合多个索引

    上面的别名context_alias聚合了context01和 context02,这样对context_alias的读操作,会操作context01和 context02。

    因为设置了参数is_write_index,所以对context_alias的写操作就是操作context02。但无法操作context01

    Rollover

    手动Rollover

    新建索引01,并设置alias

    PUT  /context01 {
        "settings" : {
            "number_of_shards":3 ,
            "number_of_replicas":1
        },
        "aliases" : {
          "context_alias" : {
            "is_write_index" : true
          }
        }
    }
    

    通过alias, 向索引中写入数据

    PUT /context_alias/_doc/0001 {
       "body":"hello world"
    }
    

    创建新索引02

    PUT /context02 {
        "settings" : {
            "number_of_shards":3 ,
            "number_of_replicas":1
        }
    }
    

    手动Rollover,alias移除context01,指向context02

    POST /_aliases {
        "actions" : [
            {
                "remove" : {
                     "index" : "context01",
                     "alias" : "context_alias"
                }
            },
            {
                "add" : {
                     "index" : "context02",
                     "alias" : "context_alias",
                     "is_write_index" : true
                }
            }
        ]
    }
    
    自动Rollover

    条件是达到5个docs,就rollover到context03

    POST /context_alias/_rollover/context03 {
        "conditions": {
            "max_docs":  5
        },
        "settings" : {
            "index.number_of_shards":3 ,
            "index.number_of_replicas":1
        }
    }'
    
    {
      "acknowledged" : true,
      "shards_acknowledged" : true,
      "old_index" : "context02",
      "new_index" : "context03",
      "rolled_over" : true,
      "dry_run" : false,
      "conditions" : {
        "[max_docs: 5]" : true
      }
    }
    

    触发了max_docs达到5的条件rollover成功,自动创建新的索引并将alias指向了新的索引。

  • 相关阅读:
    yii2.0数据库查询修改等方法
    yii2.0里自己写的源码上传图片
    解决yii2.0里url重写引用js路径问题(@web/的用法)
    yii2.0中解决post的400错误
    yii2.0用gii自动补全代码做的简单增删改查,以及图片上传和展示
    yii2.0中url重写实现方法
    (转)openssl 命令: openssl req 命令详解
    Nodejs搭建音视频通信-信令服务器 总结
    【转】阿里架构总监一次讲透中台架构,13页PPT精华详解
    (转)SSL工作原理
  • 原文地址:https://www.cnblogs.com/wshenjin/p/15160383.html
Copyright © 2011-2022 走看看