2026-06-15 15:18:21 +02:00
|
|
|
package es
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"encoding/json"
|
|
|
|
|
"fmt"
|
|
|
|
|
|
|
|
|
|
"codeberg.org/scip/esctl/pkg/cfg"
|
|
|
|
|
"codeberg.org/scip/esctl/pkg/printer"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
type TplTemplateData struct {
|
|
|
|
|
Settings map[string]any `json:"settings"`
|
|
|
|
|
Aliases map[string]any `json:"aliases"`
|
|
|
|
|
Lifecycle map[string]any `json:"lifecycle"`
|
|
|
|
|
Mappings map[string]any `json:"mappings"`
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
type TplTemplate struct {
|
|
|
|
|
Template TplTemplateData `json:"template"`
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
type TplTpl struct {
|
|
|
|
|
IndexTemplate TplTemplate `json:"index_template"`
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
type Tpl struct {
|
|
|
|
|
IndexTemplates []TplTpl `json:"index_templates"`
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func getIndexTemplateSettings(conf *cfg.Config, tplname string, table *printer.Table) error {
|
2026-07-03 10:25:57 +02:00
|
|
|
raw, err := CallAPI(conf, "GET", "/_index_template/"+tplname+"?flat_settings", "")
|
2026-06-15 15:18:21 +02:00
|
|
|
if err != nil {
|
|
|
|
|
return err
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
data := Tpl{}
|
|
|
|
|
if err = json.Unmarshal(raw, &data); err != nil {
|
|
|
|
|
return err
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if conf.Debug {
|
2026-07-03 10:07:11 +02:00
|
|
|
output, err := prettyfiJson(conf, raw)
|
|
|
|
|
if err != nil {
|
2026-06-15 15:18:21 +02:00
|
|
|
return err
|
|
|
|
|
}
|
2026-07-07 23:46:43 +02:00
|
|
|
|
2026-07-03 10:07:11 +02:00
|
|
|
fmt.Println(output)
|
2026-06-15 15:18:21 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if len(data.IndexTemplates) == 0 {
|
|
|
|
|
return fmt.Errorf("index_template %s not found", tplname)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
tpl := data.IndexTemplates[0].IndexTemplate.Template.Settings
|
|
|
|
|
for topic, val := range tpl {
|
2026-07-07 07:29:03 +02:00
|
|
|
table.AddRow(topic, val)
|
2026-06-15 15:18:21 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return nil
|
|
|
|
|
}
|