首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >Elasticsearch——Rollover的正确使用姿势

Elasticsearch——Rollover的正确使用姿势

原创
作者头像
WeldonWang
修改2024-04-15 16:39:59
1.6K0
修改2024-04-15 16:39:59
举报

一、常见报错信息

# kibana-Index Management页面报错
Index lifecycle error
illegal_argument_exception: index.lifecycle.rollover_alias [niosec-endpointsecurity-huorong-all] does not point to index [niosec-endpointsecurity-huorong-prod]

Index lifecycle error
illegal_argument_exception: index.lifecycle.rollover_alias [niosec-endpointsecurity-huorong-prod] does not point to index [niosec-endpointsecurity-huorong-prod]

二、操作步骤

https://www.elastic.co/guide/en/elasticsearch/reference/7.17/ilm-rollover.html

https://www.elastic.co/guide/en/elasticsearch/reference/7.17/indices-rollover-index.html#roll-over-index-alias-with-write-index

  • The index name must match the pattern ^.*-\d+$, for example (my-index-000001). The index.lifecycle.rollover_alias must be configured as the alias to roll over. The index must be the write index for the alias.
1. 创建索引(索引名称必须得满足以上3个条件)
# 创建索引并指定lifecycle与aliases属性
PUT %3Cmy-index-%7Bnow%2Fd%7D-000001%3E
{
  "settings": {
    "index.lifecycle.name": "my_policy",
    "index.lifecycle.rollover_alias": "my_data"
  },
  "aliases": {
    "my_data": {
      "is_write_index": true
    }
  }
}
# 返回
{
  "acknowledged" : true,
  "shards_acknowledged" : true,
  "index" : "my-index-2023.03.09-000001"
}

___

  • 如果是已有index名称(xxxxxx)不满足条件,则需要reindex其到xxxxxx-000001
POST _reindex
{
  "source": {
    "index": "xxxxxx"
  },
  "dest": {
    "index": "xxxxxx-000001"
  }
}
# 对其设置lifecycle属性
PUT xxxxxx-000001/_settings
{
  "index.lifecycle.name": "my_policy",
  "index.lifecycle.rollover_alias": "my_data"
}
# 对其添加aliases
PUT xxxxxx-000001/_aliases/my_data
{
    "is_write_index": true
}

https://www.elastic.co/guide/en/elasticsearch/reference/7.17/ilm-rollover.html

2. 创建生命周期策略
PUT _ilm/policy/my_policy/
{
  "policy": {
    "phases": {
      "hot": {
        "actions": {
          "rollover" : {
            "max_primary_shard_size": "50GB"
          }
        }
      }
    }
  }
}

具体滚动策略根据业务需要自行选择 https://www.elastic.co/guide/en/elasticsearch/reference/7.17/ilm-rollover.html

3. 验证rollover api
# 写入一条数据
PUT my-index-000001/_doc/1
{
  "name": "weldon",
  "address": "陕西省西安市"
}
# 返回
{
  "_index" : "my-index-000001",
  "_type" : "_doc",
  "_id" : "1",
  "_version" : 1,
  "result" : "created",
  "_shards" : {
    "total" : 2,
    "successful" : 2,
    "failed" : 0
  },
  "_seq_no" : 0,
  "_primary_term" : 1
}

# 验证当前索引设置、alias指向
GET _cat/indices/my-index*?v
GET my-index-000001/_settings
GET my-index-000001/_alias
GET _alias/my_data
# 返回见下图

# 执行rollover apiapi,我这里max_docs指定的是1哦(因为我只写入了1条数据),如果指定为2则不满足rollover条件,conditions返回就为false
POST my_data/_rollover
{
  "conditions": {
    "max_docs": 1
  }
}
# 返回
{
  "acknowledged" : true,
  "shards_acknowledged" : true,
  "old_index" : "my-index-000001",
  "new_index" : "my-index-000002",
  "rolled_over" : true,
  "dry_run" : false,
  "conditions" : {
    "[max_docs: 1]" : true
  }
}

https://www.elastic.co/guide/en/elasticsearch/reference/7.17/indices-rollover-index.html#roll-over-index-alias-with-write-index

rollover前GET _cat/indices/my-index*?v
rollover前GET _cat/indices/my-index*?v
rollover后GET _cat/indices/my-index*?v
rollover后GET _cat/indices/my-index*?v

原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。

如有侵权,请联系 cloudcommunity@tencent.com 删除。

原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。

如有侵权,请联系 cloudcommunity@tencent.com 删除。

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • 一、常见报错信息
  • 二、操作步骤
    • 1. 创建索引(索引名称必须得满足以上3个条件)
      • 2. 创建生命周期策略
        • 3. 验证rollover api
        相关产品与服务
        Elasticsearch Service
        腾讯云 Elasticsearch Service(ES)是云端全托管海量数据检索分析服务,拥有高性能自研内核,集成X-Pack。ES 支持通过自治索引、存算分离、集群巡检等特性轻松管理集群,也支持免运维、自动弹性、按需使用的 Serverless 模式。使用 ES 您可以高效构建信息检索、日志分析、运维监控等服务,它独特的向量检索还可助您构建基于语义、图像的AI深度应用。
        领券
        问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档