mirror of
https://codeberg.org/scip/esctl.git
synced 2026-08-24 09:44:17 +02:00
add index alias delete (#20)
This commit is contained in:
@@ -31,10 +31,11 @@ import (
|
||||
)
|
||||
|
||||
const (
|
||||
Version string = `v0.0.12`
|
||||
Version string = `v0.0.13`
|
||||
)
|
||||
|
||||
var (
|
||||
// initialized during build, see Makefile:buildlocal
|
||||
APIVERSION, GOVERSION, BUILD, COMMIT, BRANCH string
|
||||
)
|
||||
|
||||
|
||||
@@ -24,16 +24,15 @@ import (
|
||||
"strings"
|
||||
|
||||
"codeberg.org/scip/esctl/pkg/cfg"
|
||||
"codeberg.org/scip/esctl/pkg/printer"
|
||||
"codeberg.org/scip/esctl/pkg/printer"
|
||||
)
|
||||
|
||||
// FIXME: add filter support, see IndexCreate mapping
|
||||
func IndexAliasCreate(conf *cfg.Config, index, alias string) error {
|
||||
create := conf.DefaultCluster.ES.Indices.PutAlias(index, alias).
|
||||
res, err := conf.DefaultCluster.ES.Indices.PutAlias(index, alias).
|
||||
Header("content-type", "application/json").
|
||||
Header("accept", "application/json")
|
||||
|
||||
res, err := create.Do(context.Background())
|
||||
Header("accept", "application/json").
|
||||
Do(context.Background())
|
||||
|
||||
slog.Debug("create alias", "result", res)
|
||||
|
||||
@@ -52,12 +51,11 @@ func IndexAliasList(conf *cfg.Config) error {
|
||||
filter = *regexp.MustCompile(conf.Filter[0])
|
||||
}
|
||||
|
||||
create := conf.DefaultCluster.ES.Indices.GetAlias().
|
||||
res, err := conf.DefaultCluster.ES.Indices.GetAlias().
|
||||
Index("_all").
|
||||
Header("content-type", "application/json").
|
||||
Header("accept", "application/json")
|
||||
|
||||
res, err := create.Do(context.Background())
|
||||
Header("accept", "application/json").
|
||||
Do(context.Background())
|
||||
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to list index aliases: %s", err)
|
||||
@@ -100,3 +98,18 @@ func IndexAliasList(conf *cfg.Config) error {
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func IndexAliasDelete(conf *cfg.Config, index, alias string) error {
|
||||
res, err := conf.DefaultCluster.ES.Indices.DeleteAlias(index, alias).
|
||||
Header("content-type", "application/json").
|
||||
Header("accept", "application/json").
|
||||
Do(context.Background())
|
||||
|
||||
slog.Debug("delete alias", "result", res)
|
||||
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to delete index alias: %s", err)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user