
我正在尝试从 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 字段。
立即学习“go语言免费学习笔记(深入)”;
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 策略的详细内容,更多请关注php中文网其它相关文章!
每个人都需要一台速度更快、更稳定的 PC。随着时间的推移,垃圾文件、旧注册表数据和不必要的后台进程会占用资源并降低性能。幸运的是,许多工具可以让 Windows 保持平稳运行。
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号