feat: 增加ism管理接口
test: 索引模板和ism的单元测试和集成测试
This commit is contained in:
@@ -62,7 +62,37 @@ func PutTemplate(ctx context.Context, c *client.Client, name string, template *T
|
||||
return fmt.Errorf("%w: template name is required", ErrInvalidTemplate)
|
||||
}
|
||||
|
||||
body, err := json.Marshal(template)
|
||||
// Build template object with only non-empty fields
|
||||
templateObj := make(map[string]any)
|
||||
if len(template.Settings) > 0 {
|
||||
templateObj["settings"] = template.Settings
|
||||
}
|
||||
if len(template.Mappings) > 0 {
|
||||
templateObj["mappings"] = template.Mappings
|
||||
}
|
||||
if len(template.Aliases) > 0 {
|
||||
templateObj["aliases"] = template.Aliases
|
||||
}
|
||||
|
||||
// Wrap template in template field for the API
|
||||
requestBody := map[string]any{
|
||||
"index_patterns": template.IndexPatterns,
|
||||
}
|
||||
|
||||
// Only add template field if it has content
|
||||
if len(templateObj) > 0 {
|
||||
requestBody["template"] = templateObj
|
||||
}
|
||||
|
||||
// Add optional fields
|
||||
if template.Priority > 0 {
|
||||
requestBody["priority"] = template.Priority
|
||||
}
|
||||
if template.Version > 0 {
|
||||
requestBody["version"] = template.Version
|
||||
}
|
||||
|
||||
body, err := json.Marshal(requestBody)
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to marshal template: %w", err)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user