mirror of
https://codeberg.org/scip/esctl.git
synced 2026-08-24 05:04:18 +02:00
enhanced default cluster selection, add 'cluster switch', overhaul json header setting (#47)
This commit is contained in:
@@ -33,9 +33,7 @@ import (
|
||||
|
||||
// used for completion
|
||||
func IndexTemplateList(conf *cfg.Config) error {
|
||||
res, err := conf.DefaultCluster.ES.Indices.GetIndexTemplate().
|
||||
Header("content-type", "application/json").
|
||||
Header("accept", "application/json").
|
||||
res, err := conf.DefaultCluster.ES().Indices.GetIndexTemplate().
|
||||
Do(context.Background())
|
||||
|
||||
if err != nil {
|
||||
@@ -65,10 +63,8 @@ func IndexTemplateList(conf *cfg.Config) error {
|
||||
}
|
||||
|
||||
func IndexTemplateShow(conf *cfg.Config, tplname string) error {
|
||||
res, err := conf.DefaultCluster.ES.Indices.GetIndexTemplate().
|
||||
res, err := conf.DefaultCluster.ES().Indices.GetIndexTemplate().
|
||||
Name(tplname).
|
||||
Header("content-type", "application/json").
|
||||
Header("accept", "application/json").
|
||||
Do(context.Background())
|
||||
|
||||
if err != nil {
|
||||
@@ -158,9 +154,7 @@ func IndexTemplateCreate(conf *cfg.Config, name string, mappings []string) error
|
||||
settings := esdsl.NewIndexSettings()
|
||||
maps := esdsl.NewIndexTemplateMapping()
|
||||
|
||||
create := conf.DefaultCluster.ES.Indices.PutIndexTemplate(name).
|
||||
Header("content-type", "application/json").
|
||||
Header("accept", "application/json")
|
||||
create := conf.DefaultCluster.ES().Indices.PutIndexTemplate(name)
|
||||
|
||||
if conf.Shards > 0 {
|
||||
settings = settings.NumberOfShards(strconv.Itoa(conf.Shards))
|
||||
@@ -243,10 +237,8 @@ func IndexTemplateModify(conf *cfg.Config, name string, mappings []string) error
|
||||
maps := esdsl.NewIndexTemplateMapping()
|
||||
|
||||
// load existing index mapping
|
||||
res, err := conf.DefaultCluster.ES.Indices.GetIndexTemplate().
|
||||
res, err := conf.DefaultCluster.ES().Indices.GetIndexTemplate().
|
||||
Name(name).
|
||||
Header("content-type", "application/json").
|
||||
Header("accept", "application/json").
|
||||
Do(context.Background())
|
||||
|
||||
if err != nil {
|
||||
@@ -262,9 +254,7 @@ func IndexTemplateModify(conf *cfg.Config, name string, mappings []string) error
|
||||
tpl := res.IndexTemplates[0]
|
||||
|
||||
// our modify PUT request
|
||||
modify := conf.DefaultCluster.ES.Indices.PutIndexTemplate(name).
|
||||
Header("content-type", "application/json").
|
||||
Header("accept", "application/json")
|
||||
modify := conf.DefaultCluster.ES().Indices.PutIndexTemplate(name)
|
||||
|
||||
// load existing settings, if any
|
||||
settings := tpl.IndexTemplate.Template.Settings
|
||||
@@ -355,9 +345,7 @@ func IndexTemplateModify(conf *cfg.Config, name string, mappings []string) error
|
||||
}
|
||||
|
||||
func IndexTemplateDelete(conf *cfg.Config, name string) error {
|
||||
_, err := conf.DefaultCluster.ES.Indices.DeleteIndexTemplate(name).
|
||||
Header("content-type", "application/json").
|
||||
Header("accept", "application/json").
|
||||
_, err := conf.DefaultCluster.ES().Indices.DeleteIndexTemplate(name).
|
||||
Do(context.Background())
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to delete index template: %s", esErrorString(err))
|
||||
@@ -370,7 +358,7 @@ func IndexTemplateDelete(conf *cfg.Config, name string) error {
|
||||
// find indices matching those, find their associated aliases and
|
||||
// rollover all we find. Only run when conf.Rollover==true
|
||||
func rolloverAliasIndexTemplate(conf *cfg.Config, name string) error {
|
||||
res, err := conf.DefaultCluster.ES.Indices.GetIndexTemplate().
|
||||
res, err := conf.DefaultCluster.ES().Indices.GetIndexTemplate().
|
||||
Name(name).
|
||||
Do(context.Background())
|
||||
|
||||
@@ -389,7 +377,7 @@ func rolloverAliasIndexTemplate(conf *cfg.Config, name string) error {
|
||||
|
||||
// find all aliases matching the patterns
|
||||
for _, pattern := range patterns {
|
||||
res, err := conf.DefaultCluster.ES.Indices.ResolveIndex(pattern).
|
||||
res, err := conf.DefaultCluster.ES().Indices.ResolveIndex(pattern).
|
||||
Do(context.Background())
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to resolve index pattern: %s", esErrorString(err))
|
||||
|
||||
Reference in New Issue
Block a user