elasticsearch rollover index

rollover作用

当ES索引过大时,rollover,满足条件后,新建索引,将索引别名转向新索引。


rollover用法

1、创建索引,设置别名(或者通过logs-*创建索引模板)

http://192.168.0.80:9200/logs-000001

{

  "aliases": {

    "logs_write": {}

  }

}

2、通过别名,写入数据

3、执行rollover

http://192.168.0.80:9200/logs_write/_rollover

{

  "conditions": {

    "max_age":   "7d",

    "max_docs":  2,

     "max_size":  "5g"(6以后的版本才适用)

  }

}

结果:

{

    "old_index": "logs-2018.11.07-1",

    "new_index": "logs-2018.11.07-000002",(新索引名)

    "rolled_over": true,(rollover成功)

    "dry_run": false,

    "acknowledged": true,

    "shards_acknowledged": true,

    "conditions": {

        "[max_docs: 2]": true (满足该条件)

    }

}


rollover索引命名

1、索引按照【”-”+数字】的形式结尾),新创建的索引数字+1,数字为6位,不够前面以0补齐(如上rollover命名)

2、索引不符合命名规范,rollover时需要自定义新索引名称【POST /write_test_indices/_rollover/新索引名】

3、按照日期形式命名

# PUT / with URI encoding:

PUT /%3Clogs-%7Bnow%2Fd%7D-1%3E

{

  "aliases": {

    "logs_write": {}

  }

}

参考日期形式写法:https://www.elastic.co/guide/en/elasticsearch/reference/5.4/date-math-index-names.html


使用注意事项

1、别名和索引名不能重复

2、rollover操作的别名是能够进行写操作的别名,只指向一个索引(最新索引);

3、6.5以后的版本支持is_write_index,默认为null,别名也只指向最新索引

当操作,is_write_index=true时,

执行rollover后,别名logs的写指向最新索引,查询指向所有rollover下的索引。

例子:

PUT my_logs_index-000001{ "aliases": { "logs": { "is_write_index": true }}}

PUT logs/_doc/1

{

  "message": "a dummy log"

}

POST logs/_refresh

POST /logs/_rollover

{

  "conditions": {

    "max_docs":  "1"

  }

}

PUT logs/_doc/2

{

  "message": "a newer log"

}

别名操作写入了新索引中:

{

  "_index" : "my_logs_index-000002",

  "_type" : "_doc",

  "_id" : "2",

  "_version" : 1,

  "result" : "created",

  "_shards" : {

    "total" : 2,

    "successful" : 1,

    "failed" : 0

  },

  "_seq_no" : 0,

  "_primary_term" : 1

}

索引的别名:

{

  "my_logs_index-000002": {

    "aliases": {

      "logs": { "is_write_index": true }

    }

  },

  "my_logs_index-000001": {

    "aliases": {

      "logs": { "is_write_index" : false }

    }

  }

}

你可能感兴趣的:(elasticsearch rollover index)