【问题标题】:How to create ElasticSearch policy from Golang client如何从 Golang 客户端创建 ElasticSearch 策略
【发布时间】:2022-12-03 16:20:05
【问题描述】:

我正在尝试从 Elastic Golang 客户端 olivere 创建索引生命周期管理 (ILM) 策略,以删除超过 3 个月的索引(使用“每天索引”模式)。是这样的:

{
  "policy": {
    "phases": {      
      "delete": {
        "min_age": "90d",
        "actions": {
          "delete": {}
        }
      }
    }
  }
}

我可以在 lib 的源代码中看到它的结构:XPackIlmPutLifecycleService 具有以下字段:

type XPackIlmPutLifecycleService struct {
    client *Client

    pretty     *bool       // pretty format the returned JSON response
    human      *bool       // return human readable values for statistics
    errorTrace *bool       // include the stack trace of returned errors
    filterPath []string    // list of filters used to reduce the response
    headers    http.Header // custom request-level HTTP headers

    policy        string
    timeout       string
    masterTimeout string
    flatSettings  *bool
    bodyJson      interface{}
    bodyString    string
}

这是文档link。但是我有点困惑如何使用它来创建策略来完成工作,因为它似乎缺少一些字段(例如 min_age 来设置索引的 TTL)。通过此客户端创建 ILM 策略的正确方法是什么。

【问题讨论】:

    标签: go elasticsearch go-olivere


    【解决方案1】:

    可以参考测试代码!基本上你可以把 json 放到 body 字段。 https://github.com/olivere/elastic/blob/release-branch.v7/xpack_ilm_test.go#L15-L31

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-06-02
      • 2018-05-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多