用 Golang 客户端创建 ElasticSearch 策略的方法是什么?
时间:2024-02-08
浏览:175
作者:佚名
各位小伙伴们,大家好呀!看看今天我又给各位带来了什么文章?本文标题是《用 Golang 客户端创建 ElasticSearch 策略的方法是什么?》,很明显是关于Golang的文章哈哈哈,其中内容主要会涉及到等等,如果能帮到你,觉得很不错的话,欢迎各位多多点评和分享!
问题内容
我正在尝试从 elastic golang 客户端 olivere 创建索引生命周期管理 (ilm) 策略,以删除超过 3 个月的索引(使用“每日索引”模式)。像这样的事情:
{
"policy": {
"phases": {
"delete": {
"min_age": "90d",
"actions": {
"delete": {}
}
}
}
}
}
我可以在库的源代码中看到这样的结构: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
}
这是文档链接。然而,我有点困惑如何创建使用它来完成这项工作的策略,因为它似乎缺少一些字段(例如 min_age 设置索引的 ttl)。通过此客户端创建 ilm 策略的正确方法是什么。
正确答案
可以参考测试代码!基本上你可以将 json 放入 body 字段。
testPolicyName := "test-policy"
body := `{
"policy": {
"phases": {
"delete": {
"min_age": "90d",
"actions": {
"delete": {}
}
}
}
}
}`
// Create the policy
putilm, err := client.XPackIlmPutLifecycle().Policy(testPolicyName).BodyString(body).Do(context.TODO())
https://github.com /olivere/elastic/blob/release-branch.v7/xpack_ilm_test.go#l15-l31
今天关于《用 Golang 客户端创建 ElasticSearch 策略的方法是什么?》的内容介绍就到此结束,如果有什么疑问或者建议,可以在golang学习网公众号下多多回复交流;文中若有不正之处,也希望回复留言以告知!
本文内容来源于互联网,如有侵权请联系删除。
近期热门
11.18
11.15
站内热门
最新文章
11.28
热门专题
