mirror of
https://codeberg.org/scip/esctl.git
synced 2026-08-24 06:34:18 +02:00
@@ -28,7 +28,7 @@ import (
|
||||
)
|
||||
|
||||
const (
|
||||
Version string = `v0.0.21`
|
||||
Version string = `v0.0.22`
|
||||
)
|
||||
|
||||
var (
|
||||
@@ -51,6 +51,7 @@ type Config struct {
|
||||
Failed, Partials bool // index: flags
|
||||
Shards, Replicas int // index create+allocation: -s -r
|
||||
Wait bool // index create: -w
|
||||
Policy string // index create: -p
|
||||
Primary bool // index allocation: -p
|
||||
Searchable bool // index fields: -s
|
||||
Aggretable bool // index fields: -a
|
||||
|
||||
@@ -28,6 +28,7 @@ import (
|
||||
|
||||
"codeberg.org/scip/esctl/pkg/cfg"
|
||||
"codeberg.org/scip/esctl/pkg/printer"
|
||||
"github.com/alecthomas/repr"
|
||||
"github.com/elastic/go-elasticsearch/v9/typedapi/cat/indices"
|
||||
"github.com/elastic/go-elasticsearch/v9/typedapi/esdsl"
|
||||
"github.com/elastic/go-elasticsearch/v9/typedapi/types/enums/healthstatus"
|
||||
@@ -131,6 +132,9 @@ func IndexShow(conf *cfg.Config, indexpattern string) error {
|
||||
return fmt.Errorf("failed to get index: %s", esErrorString(err))
|
||||
}
|
||||
|
||||
slog.Debug("index show", "index", res)
|
||||
repr.Println(res)
|
||||
|
||||
for name, index := range res {
|
||||
fields := make([]string, len(index.Mappings.Properties))
|
||||
idx := 0
|
||||
@@ -139,7 +143,7 @@ func IndexShow(conf *cfg.Config, indexpattern string) error {
|
||||
idx++
|
||||
}
|
||||
|
||||
table := printer.NewTable(conf, 2, 5)
|
||||
table := printer.NewTable(conf, 2, 7)
|
||||
table.Addheaders("index property", "value")
|
||||
|
||||
ts, err := strconv.ParseInt(index.Settings.Index.CreationDate.(string), 10, 64)
|
||||
@@ -155,9 +159,17 @@ func IndexShow(conf *cfg.Config, indexpattern string) error {
|
||||
{"shards", *index.Settings.Index.NumberOfShards},
|
||||
{"created", created.Format("2006-01-02 15:04:05")},
|
||||
{"uuid", *index.Settings.Index.Uuid},
|
||||
{"version", *index.Settings.Index.Version.Created},
|
||||
{"fields", strings.Join(fields, ",")},
|
||||
}
|
||||
|
||||
if index.Settings.Index.Lifecycle != nil {
|
||||
table.Entries = append(table.Entries, [][]string{
|
||||
{"ilm policy", *index.Settings.Index.Lifecycle.Name},
|
||||
{"ilm rollover alias", *index.Settings.Index.Lifecycle.RolloverAlias},
|
||||
}...)
|
||||
}
|
||||
|
||||
if err := table.Print(); err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -178,10 +190,10 @@ func IndexCreate(conf *cfg.Config, index string, mappings []string) error {
|
||||
}
|
||||
|
||||
if conf.Shards > 0 {
|
||||
settings = settings.NumberOfShards(strconv.Itoa(conf.Shards))
|
||||
settings.NumberOfShards(strconv.Itoa(conf.Shards))
|
||||
}
|
||||
if conf.Replicas > 0 {
|
||||
settings = settings.NumberOfReplicas(strconv.Itoa(conf.Replicas))
|
||||
settings.NumberOfReplicas(strconv.Itoa(conf.Replicas))
|
||||
}
|
||||
|
||||
if len(mappings) > 0 {
|
||||
@@ -208,6 +220,13 @@ func IndexCreate(conf *cfg.Config, index string, mappings []string) error {
|
||||
create.Mappings(maps)
|
||||
}
|
||||
|
||||
if conf.Policy != "" {
|
||||
settings.Lifecycle(
|
||||
esdsl.NewIndexSettingsLifecycle().
|
||||
Name(conf.Policy).
|
||||
RolloverAlias(index))
|
||||
}
|
||||
|
||||
_, err := create.Settings(settings).
|
||||
Do(context.Background())
|
||||
|
||||
@@ -281,6 +300,7 @@ func IndexAllocation(conf *cfg.Config, index string) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
/*
|
||||
func IndexModify(conf *cfg.Config, index string) error {
|
||||
settings := esdsl.NewIndexSettings().NumberOfReplicas(strconv.Itoa(conf.Replicas))
|
||||
|
||||
@@ -294,6 +314,7 @@ func IndexModify(conf *cfg.Config, index string) error {
|
||||
|
||||
return nil
|
||||
}
|
||||
*/
|
||||
|
||||
func IndexFields(conf *cfg.Config, index string) error {
|
||||
res, err := conf.DefaultCluster.ES().FieldCaps().
|
||||
|
||||
@@ -157,11 +157,17 @@ func IndexTemplateCreate(conf *cfg.Config, name string, mappings []string) error
|
||||
create := conf.DefaultCluster.ES().Indices.PutIndexTemplate(name)
|
||||
|
||||
if conf.Shards > 0 {
|
||||
settings = settings.NumberOfShards(strconv.Itoa(conf.Shards))
|
||||
settings.NumberOfShards(strconv.Itoa(conf.Shards))
|
||||
}
|
||||
|
||||
if conf.Replicas > 0 {
|
||||
settings = settings.NumberOfReplicas(strconv.Itoa(conf.Replicas))
|
||||
settings.NumberOfReplicas(strconv.Itoa(conf.Replicas))
|
||||
}
|
||||
|
||||
if conf.Policy != "" {
|
||||
settings.Lifecycle(
|
||||
esdsl.NewIndexSettingsLifecycle().
|
||||
Name(conf.Policy))
|
||||
}
|
||||
|
||||
if conf.Stream {
|
||||
@@ -284,6 +290,10 @@ func IndexTemplateModify(conf *cfg.Config, name string, mappings []string) error
|
||||
*settings.Mode = conf.Mode
|
||||
}
|
||||
|
||||
if conf.Policy != "" {
|
||||
settings.Lifecycle.Name = &conf.Policy
|
||||
}
|
||||
|
||||
if len(mappings) > 0 {
|
||||
typemaps, err := modMappings(mappings)
|
||||
if err != nil {
|
||||
|
||||
Reference in New Issue
Block a user