mirror of
https://codeberg.org/scip/esctl.git
synced 2026-08-24 08:04:17 +02:00
add index template {ls,sh} (#33)
This commit is contained in:
61
pkg/es/index_template_settings.go
Normal file
61
pkg/es/index_template_settings.go
Normal file
@@ -0,0 +1,61 @@
|
||||
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 {
|
||||
raw, err := CallAPI(conf, "GET", "/_index_template/"+tplname, "")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
data := Tpl{}
|
||||
if err = json.Unmarshal(raw, &data); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if conf.Debug {
|
||||
if err := prettyfiJson(conf, raw); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
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 {
|
||||
paths := getJsonPath(map[string]string{}, val.(map[string]any), topic)
|
||||
|
||||
for setting, value := range paths {
|
||||
table.Entries = append(table.Entries, []string{setting, fmt.Sprintf("%v", value)})
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
Reference in New Issue
Block a user