Elascticsearch基于ILM政策来保留应用程序/消费者

发布于 2025-01-24 07:48:05 字数 2141 浏览 2 评论 0原文

我有一项Elasticsearch服务,这是我们应用程序的记录后端。 应用程序代码不向我们打开,因此我们无法更改应用程序。 应用程序正在通过HTTP的某些流中调用Elasticsearch,如下所示。

POST order-service-2022.04.23/_doc
{
  "message": "order created",
  "@timestamp": "1591890613"
}

在后来,他们打电话给以下相同的服务。只有日期正在改变。

POST order-service-2022.04.24/_doc
{
  "message": "order created",
  "@timestamp": "1591890613"
}

问题是我们无法设置ILM策略,而不会改变客户端行为。 目的是根据某些条件滚动索引,因为我们无法更改应用程序代码,因此HTTP调用应该像应用程序一样。 我们尝试的是:

索引模板:

PUT _index_template/order_template
{
  "index_patterns": [
    "order-*-*"
  ],
  "template": {
    "settings": {
      "number_of_shards": 1,
      "number_of_replicas": 0,
      "index.lifecycle.name": "order_policy",
      "index.lifecycle.rollover_alias": "order"
    }
  }
}

ILM策略

PUT _ilm/policy/order_policy
{
  "policy": {
    "phases": {
      "hot": {                                
        "actions": {
          "rollover": {
            "max_primary_shard_size": "1GB", 
            "max_age": "1d",
            "max_docs": 500
          }
        }
      },
      "delete": {
        "min_age": "2d",                     
        "actions": {
          "delete": {}                        
        }
      }
    }
  }
}

种子索引:

PUT order-service-2022.04.23
{
  "aliases": {
    "order": {
      "is_write_index": true
    }
  }
}

在DOC插入到弹性成功结果时。

但是在汇总期间,只有一天的时间以下是

POST /order/_rollover
{
  "error" : {
    "root_cause" : [
      {
        "type" : "illegal_argument_exception",
        "reason" : "index name [order-service-2022.04.23] does not match pattern '^.*-\\d+$'"
      }
    ],
    "type" : "illegal_argument_exception",
    "reason" : "index name [order-service-2022.04.23] does not match pattern '^.*-\\d+$'"
  },
  "status" : 400
}

第二期,即未来几天如何汇总,因为没有别名。

I have an elasticsearch service which is a logging backend for our applications.
Application code is not open to us, so we can not change the application.
applications are calling elasticsearch in certain points in flow via http as below.

POST order-service-2022.04.23/_doc
{
  "message": "order created",
  "@timestamp": "1591890613"
}

in the later day they are calling the same service like below. only date is changing.

POST order-service-2022.04.24/_doc
{
  "message": "order created",
  "@timestamp": "1591890613"
}

The problem is we can not set up an ILM policy with out changing the client behaviour.
The aim is roll over the index based on some criteria, since we can not change the application code, http call should be like that in application side.
what we have tried is :

index template :

PUT _index_template/order_template
{
  "index_patterns": [
    "order-*-*"
  ],
  "template": {
    "settings": {
      "number_of_shards": 1,
      "number_of_replicas": 0,
      "index.lifecycle.name": "order_policy",
      "index.lifecycle.rollover_alias": "order"
    }
  }
}

ilm policy

PUT _ilm/policy/order_policy
{
  "policy": {
    "phases": {
      "hot": {                                
        "actions": {
          "rollover": {
            "max_primary_shard_size": "1GB", 
            "max_age": "1d",
            "max_docs": 500
          }
        }
      },
      "delete": {
        "min_age": "2d",                     
        "actions": {
          "delete": {}                        
        }
      }
    }
  }
}

seed index :

PUT order-service-2022.04.23
{
  "aliases": {
    "order": {
      "is_write_index": true
    }
  }
}

during doc insert to elastic successful result.

but during rollup for only one day give below exception

POST /order/_rollover
{
  "error" : {
    "root_cause" : [
      {
        "type" : "illegal_argument_exception",
        "reason" : "index name [order-service-2022.04.23] does not match pattern '^.*-\\d+

second issue how the up coming days need to rollup since no alias for them..

" } ], "type" : "illegal_argument_exception", "reason" : "index name [order-service-2022.04.23] does not match pattern '^.*-\\d+

second issue how the up coming days need to rollup since no alias for them..

" }, "status" : 400 }

second issue how the up coming days need to rollup since no alias for them..

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

一片旧的回忆 2025-01-31 07:48:05

首先,看起来应用程序代码每天都在更改索引名称,因此应用程序代码正在进行“翻转”。因此,如果您无法更改应用程序代码,则您已经具有一些翻转逻辑,但直接在应用程序代码中实现。

您遇到的错误是因为初始种子索引必须以一个顺序编号结尾否则它将无法使用。

正则表达式^。* - \\ d+$表示“以一个或多个数字结尾的任何索引名称”

                            add this
                               |
                               v
PUT order-service-2022.04.23-00001
{
  "aliases": {
    "order": {
      "is_write_index": true
    }
  }
}

这也意味着组成索引名称的应用程序代码将无法知道当前序列号是什么,因此,必须直接写入order写别名,否则它将无法使用。

First, it looks like the application code is doing the "rollover" by itself since it's changing the index name everyday. So if you can't change the application code, you sort of already have some rollover logic but implemented directly in your application code.

The error you get is because the initial seed index MUST end with a sequential number otherwise it won't work.

The regular expression ^.*-\\d+$ means "any index name that ends with one or more digits"

                            add this
                               |
                               v
PUT order-service-2022.04.23-00001
{
  "aliases": {
    "order": {
      "is_write_index": true
    }
  }
}

This also means that the application code that makes up the index name would NOT be able to know what the current sequence number is, and hence, MUST write directly to the order write alias instead, otherwise it's not going to work.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文