mirror of
https://codeberg.org/scip/esctl.git
synced 2026-08-24 04:54:18 +02:00
add snapshot commands
This commit is contained in:
@@ -18,16 +18,23 @@ package es
|
||||
|
||||
import (
|
||||
"context"
|
||||
"log"
|
||||
"fmt"
|
||||
"log/slog"
|
||||
|
||||
"codeberg.org/scip/esctl/pkg/cfg"
|
||||
"github.com/elastic/go-elasticsearch/v9/typedapi/types/enums/healthstatus"
|
||||
)
|
||||
|
||||
func IndexList(conf *cfg.Config) error {
|
||||
res, err := conf.ES.Cat.Indices().Do(context.Background())
|
||||
cat := conf.ES.Cat.Indices()
|
||||
|
||||
if conf.Failed {
|
||||
cat = cat.Health(healthstatus.Red)
|
||||
}
|
||||
|
||||
res, err := cat.Do(context.Background())
|
||||
if err != nil {
|
||||
log.Fatalf("Error getting indicies: %s", err)
|
||||
return fmt.Errorf("Error getting indicies: %s", err)
|
||||
}
|
||||
|
||||
slog.Debug("ES result", "indicies", res)
|
||||
@@ -40,9 +47,8 @@ func IndexList(conf *cfg.Config) error {
|
||||
}
|
||||
}
|
||||
|
||||
table := NewTable(size)
|
||||
|
||||
table.headers = []string{bold("NAME"), bold("SIZE"), bold("DOCSCOUNT")}
|
||||
table := NewTable(3, size)
|
||||
table.Addheaders("name", "size", "docscount")
|
||||
|
||||
for idx, index := range res {
|
||||
name := Colorize(*index.Health, *index.Index)
|
||||
@@ -59,3 +65,16 @@ func IndexList(conf *cfg.Config) error {
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func IndexShow(conf *cfg.Config, index string) error {
|
||||
res, err := conf.ES.Indices.Get(index).Do(context.Background())
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to get index: %s", err)
|
||||
}
|
||||
|
||||
slog.Debug("ES result", "index", res)
|
||||
|
||||
// FIXME: add table printer like SnapshotShow
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user