Elasticsearch中,如何使用时间滚动+ILM创建动态索引?

提问者:帅平 问题分类:搜索引擎
Elasticsearch中,如何使用时间滚动+ILM创建动态索引?
3 个回答
巴黎小甜心
巴黎小甜心
总体思路如下:
1、创建ILM策略,比如热节点保留30天,之后删除
PUT _ilm/policy/order_logs_policy
{
  "policy": {
    "phases": {
      "hot": {
        "min_age": "0ms",
        "actions": {
          "rollover": {
            "max_size": "50gb",
            "max_age": "1d"
          }
        }
      },
      "delete": {
        "min_age": "30d",
        "actions": {
          "delete": {}
        }
      }
    }
  }
}
发布于:1个月前 (03-21) IP属地:四川省
候你多时
候你多时
2、接着定义索引的模板,里面自动应用上面创建的ILM
PUT _index_template/order_logs_template
{
  "index_patterns": ["order_logs-*"],
  "template": {
    "settings": {
      "number_of_shards": 3,
      "number_of_replicas": 1,
      "index.lifecycle.name": "order_logs_policy",
      "index.routing_path": ["order_id"]  # 优化时序数据写入
    },
    "mappings": {
      "properties": {
        "order_id": { "type": "keyword" },
        "timestamp": { "type": "date" },
        "amount": { "type": "double" },
        "status": { "type": "keyword" }
      }
    }
  }
}
发布于:1个月前 (03-21) IP属地:四川省
也不长发及腰
也不长发及腰
2、接着定义索引的模板,里面自动应用上面创建的ILM
PUT _index_template/order_logs_template
{
  "index_patterns": ["order_logs-*"],
  "template": {
    "settings": {
      "number_of_shards": 3,
      "number_of_replicas": 1,
      "index.lifecycle.name": "order_logs_policy",
      "index.routing_path": ["order_id"]  # 优化时序数据写入
    },
    "mappings": {
      "properties": {
        "order_id": { "type": "keyword" },
        "timestamp": { "type": "date" },
        "amount": { "type": "double" },
        "status": { "type": "keyword" }
      }
    }
  }
}
3、初始化第一个索引,后续自动滚动
PUT order_logs-000001{  "aliases": {    "current_order_logs": {  # 查询统一走别名      "is_write_index": true    }  }}
发布于:1个月前 (03-21) IP属地:四川省
我来回答