头图

一、参考

elasticsearch 学习系列目录——更新ing

Elasticsearch基于Pipeline窗口函数实现实时聚合计算

Moving function aggregation

二、测试过程

2.1 修改ilm检测周期

indices.lifecycle.poll_interval 默认是 10min, 修改为10s

PUT _cluster/settings
{
  "persistent": {
    "indices.lifecycle.poll_interval": "10s"
  }
}

2.2 创建测试策略和模版

(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": {}
        }
      }
    }
  }
}

(2)创建模版,使用上面创建的生命周期管理策略,

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
  }
}

(3)创建初始的索引

PUT rollover_test-000001 
{
  "aliases": {
    "rollover_test_alias":{
      "is_write_index": true 
    }
  }
} 

image.png

image.png

image.png

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

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

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
      }
    }
  }
}

image.png

2.4 手动触发滚动


一曲广陵散
76 声望21 粉丝

柴米油盐酱醋茶