测试过程

备注:ES版本:7.9.3,kibana版本:7.9.3;

  1. 修改ilm检测周期
    indices.lifecycle.poll_interval 默认是 10min, 修改为10s
PUT _cluster/settings
{
  "persistent": {
    "indices.lifecycle.poll_interval": "10s"
  }
}

查看修改结果:
GET _cluster/settings

{
  "persistent" : {
    "indices" : {
      "lifecycle" : {
        "poll_interval" : "10s"
      }
    }
  },
  "transient" : { }
}
  1. 创建测试策略和模版
    创建策略,每写入5个文档,即触发滚动策略,滚出新的索引
PUT _ilm/policy/rollover_test_policy
{
  "policy": {
    "phases": {
      "hot": {
        "min_age": "0",
        "actions": {
          "set_priority": {
            "priority": 100
          },
          "rollover": {
            "max_docs": 5
          }
        }
      },
      "warm": {
        "min_age": "0",
        "actions": {
          "set_priority": {
            "priority": 50
          },
          "forcemerge": {
            "max_num_segments": 1
          }
        }
      },
      "cold": {
        "min_age": "1d",
        "actions": {
          "set_priority": {
            "priority": 0
          },
          "freeze": {}
      }
      },
      "delete": {
        "min_age": "1d",
        "actions": {
          "delete": {}
        }
      }
    }
  }
}
{
  "acknowledged" : true
}
  1. 创建模版,使用上面创建的生命周期管理策略
PUT _template/rollover_test_template
{
  "index_patterns": [
    "rollover_test-*"
  ],
  "settings": {
    "index.lifecycle.name": "rollover_test_policy",
    "index.lifecycle.rollover_alias": "rollover_test_alias",
    "number_of_replicas": 0,
    "number_of_shards": 1
  }
}
{
  "acknowledged" : true
}
  1. 创建初始的索引
PUT rollover_test-000001 
{
  "aliases": {
    "rollover_test_alias":{
      "is_write_index": true 
    }
  }
} 
{
  "acknowledged" : true,
  "shards_acknowledged" : true,
  "index" : "rollover_test-000001"
}

image.png

查看索引生命周期
GET rollover_test-000001/_ilm/explain
image.png

由上面信息,可以得到 rollover_test-000001处于 hot阶段的rollover步骤检查中

  1. 通过写入文档,自动触发rollover滚动

写入多个文档

POST /rollover_test-000001/_doc
{
  "name": "caodewang"
}

查看文档数量和内容:

GET /_cat/count/rollover_test-000001?v
GET /_cat/indices/rollover_test-000001?v

GET rollover_test-000001/_search
{
  "query": {
    "match_all": {}
  }
}

核实索引滚动成功
查看命令:GET _alias/rollover_test_alias
显示结果:

{
  "rollover_test-000001" : {
    "aliases" : {
      "rollover_test_alias" : {
        "is_write_index" : false
      }
    }
  },
  "rollover_test-000002" : {
    "aliases" : {
      "rollover_test_alias" : {
        "is_write_index" : true
      }
    }
  }
}

查看kibana上索引生命周期相关信息如下 :

image.png

image.png

image.png

参考:
https://segmentfault.com/a/11...


健身的地瓜
1 声望0 粉丝

下一篇 »
ES常用命令