ES模版及生命週期

ES模版及生命週期設置

注:集羣 elasticsearch 版本爲 v7.2.1。


一、ES索引模版設置:


1.創建模版

PUT _template/template_1

{
  "index_patterns": [
    "te*"
  ],
  "order": 1,
  "settings": {
    //"index.lifecycle.name": "my_policy",
    "number_of_shards": 6,
    "number_of_replicas": 1
  },
  "aliases": {
    "alias1": {},
    "alias2": {
      "filter": {
        "term": {
          "user": "kimchy"
        }
      },
      "routing": "kimchy"
    },
    "{index}-alias": {}
  },
  "mappings": {}
}

2.查看模版:

GET /_template/template_1
GET /_template/template_1,template_2
GET /_template/temp*
GET /_template	獲取所有

3.刪除模版:

DELETE /_template/template_1

4.模版是否存在:

HEAD _template/template_1

 

二、ES索引生命週期設置:


1.創建索引生命週期計劃:

PUT _ilm/policy/delete_policy


{
  "policy": {
    "phases": {
      "delete": {
          "min_age": "7d",
        "actions": {
          "delete" : { }
        }
      }
    }
  }
}

2.索引使用生命週期:

PUT index/_settings

{
  "index.lifecycle.name": "delete_policy"
}

3.索引模版使用生命週期:

PUT _template/template_1
{
    "index_patterns" : ["te*"],
    "order" : 1,
    "settings" : {
        "number_of_shards" : 6,
        "number_of_replicas": 1,
        "index.lifecycle.name": "my_policy"
    },
    "aliases" : {
        "alias1" : {},
        "alias2" : {
            "filter" : {
                "term" : {"user" : "kimchy" }
            },
            "routing" : "kimchy"
        },
        "{index}-alias" : {} 
    },
    "mappings": {}
}

4.查看索引生命週期:

GET _ilm/policy     獲取所有
GET _ilm/policy/<policy_id>

5.查看單個索引的生命週期計劃:

GET test/_ilm/explain

6.索引生命週期計劃執行輪詢時間:

PUT _cluster/settings

By default, ILM only checks rollover conditions every 10 minutes

{
  "transient": {
    "indices.lifecycle.poll_interval": "1m" 
  }
}

7.刪除生命週期:

DELETE _ilm/policy/<policy_id>

8.生命週期(Managing the index lifecycle)其他配置:

①索引生命週期狀態:
  GET _ilm/status

②索引生命週期開啓(關閉):
  POST _ilm/start(stop)

③生命週期運行失敗重試:
  POST /index/_ilm/retry
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章