From 504db9835dc7b2b9e86a0312d681440b968d07b4 Mon Sep 17 00:00:00 2001 From: "T. von Dein" Date: Mon, 1 Jun 2026 12:30:41 +0200 Subject: [PATCH] add sort support to search, add index fields command, fix error messages (#25) --- README.md | 4 +++ TODO.md | 24 ++++++++++++++++- cmd/index.go | 20 ++++++++++++++ cmd/search.go | 13 ++++++++++ pkg/cfg/config.go | 5 +++- pkg/es/ccr.go | 6 ++--- pkg/es/ccr_follower.go | 16 ++++++------ pkg/es/cluster_settings.go | 8 +++--- pkg/es/cluster_util.go | 6 ++--- pkg/es/doc.go | 8 +++--- pkg/es/errors.go | 40 ++++++++++++++++++++++++++++ pkg/es/index.go | 53 ++++++++++++++++++++++++++++++++------ pkg/es/index_alias.go | 6 ++--- pkg/es/node.go | 4 +-- pkg/es/repl.go | 2 +- pkg/es/search.go | 27 ++++++------------- pkg/es/search_filter.go | 42 ++++++++++++++++++++++++++++++ pkg/es/shard.go | 4 +-- pkg/es/snapshot.go | 8 +++--- 19 files changed, 233 insertions(+), 63 deletions(-) create mode 100644 pkg/es/errors.go diff --git a/README.md b/README.md index d604377..6e990e5 100644 --- a/README.md +++ b/README.md @@ -28,8 +28,11 @@ Command tree: list set status + debug doc add + delete + show help index alias @@ -40,6 +43,7 @@ Command tree: close create delete + fields list modify show diff --git a/TODO.md b/TODO.md index ebe43ce..37371d1 100644 --- a/TODO.md +++ b/TODO.md @@ -4,8 +4,30 @@ - Fix index names custom completion https://github.com/urfave/cli/issues/2332 https://github.com/urfave/cli/issues/2333 - + - index show: add more details, see screenshots - add shard explain, aka: get /_cluster/allocation/explain {"index":"yourindex", "primary": true, "shard":0} + + +- add validate: + +> GET /mock/_validate/query?rewrite=true {"from":0,"query":{"bool":{"must":[{"match_all":{}}]}},"size":20,"sort":[{"name":{"order":"desc"}}]} +{ + "valid": false +} + +- add explain to search (maybe option -e) + +> GET /mock/_explain/1780043878 {"query":{"bool":{"must":[{"match_all":{}}]}}} +{ + "_index": "mock", + "_id": "1780043878", + "matched": true, + "explanation": { + "value": 1.0, + "description": "*:*", + "details": [] + } +} diff --git a/cmd/index.go b/cmd/index.go index 159c9c2..2fae152 100644 --- a/cmd/index.go +++ b/cmd/index.go @@ -42,6 +42,7 @@ func Index(conf *cfg.Config) *cli.Command { IndexAllocation(conf), IndexModify(conf), IndexAlias(conf), + IndexFields(conf), }, } } @@ -157,6 +158,8 @@ func IndexCreate(conf *cfg.Config) *cli.Command { Name: "create", Aliases: []string{"+"}, Usage: "create a new index", + UsageText: `create ... +Valid field mapping types: integer, text, date, keyword`, Flags: []cli.Flag{ &cli.BoolFlag{ @@ -250,3 +253,20 @@ func IndexModify(conf *cfg.Config) *cli.Command { }, } } + +func IndexFields(conf *cfg.Config) *cli.Command { + return &cli.Command{ + Name: "fields", + Usage: "show info about field capabilities", + UsageText: "index fields ", + + Action: func(ctx context.Context, cmd *cli.Command) error { + index := cmd.Args().Get(0) + if index == "" { + return errors.New("no index specified") + } + + return es.IndexFields(conf, index) + }, + } +} diff --git a/cmd/search.go b/cmd/search.go index f54b814..435563f 100644 --- a/cmd/search.go +++ b/cmd/search.go @@ -100,6 +100,19 @@ func Search(conf *cfg.Config) *cli.Command { Destination: &conf.TimestampFormat, Value: "strict_date_hour_minute", }, + &cli.StringFlag{ + Name: "sort-by", + Usage: "sort by a field", + Destination: &conf.SortBy, + Value: "@timestamp", + Aliases: []string{"k"}, + }, + &cli.BoolFlag{ + Name: "ascending", + Usage: "sort in ascending order (default: descending)", + Destination: &conf.Ascending, + Aliases: []string{"a"}, + }, &cli.BoolFlag{ Name: "help-jsonpath", Usage: "show jsonPath help", diff --git a/pkg/cfg/config.go b/pkg/cfg/config.go index ebc2866..80800fb 100644 --- a/pkg/cfg/config.go +++ b/pkg/cfg/config.go @@ -34,7 +34,7 @@ import ( ) const ( - Version string = `v0.0.14` + Version string = `v0.0.15` ) var ( @@ -67,6 +67,9 @@ type Config struct { Or bool // search: -O Range string // search: -r TimestampFormat string // search: --timestamp-format + Explain bool // search: -e + SortBy string // sort: -k + Ascending bool // sort: -a Exclude string // cluster compare: -e (regexp) All, Verbose bool // cluster status: -a -v Persistent, Transient, Default bool // -p -t -D cluster settings set diff --git a/pkg/es/ccr.go b/pkg/es/ccr.go index b419896..beb2fbe 100644 --- a/pkg/es/ccr.go +++ b/pkg/es/ccr.go @@ -23,7 +23,7 @@ import ( "log/slog" "codeberg.org/scip/esctl/pkg/cfg" - "codeberg.org/scip/esctl/pkg/printer" + "codeberg.org/scip/esctl/pkg/printer" "github.com/elastic/go-elasticsearch/v9/typedapi/types" ) @@ -62,7 +62,7 @@ func CcrStatus(conf *cfg.Config, leader, follower string) error { res, err := cat.Do(context.Background()) if err != nil { - return fmt.Errorf("failed to get indicies on %s: %s", alias, err) + return fmt.Errorf("failed to get indicies on %s: %s", alias, esErrorString(err)) } indices[alias] = make(map[string]*types.IndicesRecord, len(res)) @@ -93,7 +93,7 @@ func CcrRemoteInfo(conf *cfg.Config, index string) error { Header("accept", "application/json"). Do(context.Background()) if err != nil { - return fmt.Errorf("failed to retrieve follower info: %s", err) + return fmt.Errorf("failed to retrieve follower info: %s", esErrorString(err)) } slog.Debug("ccr remote info", "info", res) diff --git a/pkg/es/ccr_follower.go b/pkg/es/ccr_follower.go index c27886a..37444b1 100644 --- a/pkg/es/ccr_follower.go +++ b/pkg/es/ccr_follower.go @@ -22,7 +22,7 @@ import ( "log/slog" "codeberg.org/scip/esctl/pkg/cfg" - "codeberg.org/scip/esctl/pkg/printer" + "codeberg.org/scip/esctl/pkg/printer" ) func getRemoteName(conf *cfg.Config) (string, error) { @@ -31,7 +31,7 @@ func getRemoteName(conf *cfg.Config) (string, error) { Header("accept", "application/json"). Do(context.Background()) if err != nil { - return "", fmt.Errorf("failed to retrieve follower info: %s", err) + return "", fmt.Errorf("failed to retrieve follower info: %s", esErrorString(err)) } remote := "" @@ -41,7 +41,7 @@ func getRemoteName(conf *cfg.Config) (string, error) { } if remote == "" { - return "", fmt.Errorf("cluster doesn't have a follower: %s", err) + return "", fmt.Errorf("cluster doesn't have a follower") } return remote, nil @@ -96,7 +96,7 @@ func CcrFollowerResume(conf *cfg.Config, index string) error { _, err := create.Do(context.Background()) if err != nil { - return fmt.Errorf("failed to resume ccr following: %s", err) + return fmt.Errorf("failed to resume ccr following: %s", esErrorString(err)) } return nil @@ -110,7 +110,7 @@ func CcrFollowerPause(conf *cfg.Config, index string) error { _, err := create.Do(context.Background()) if err != nil { - return fmt.Errorf("failed to pause ccr following: %s", err) + return fmt.Errorf("failed to pause ccr following: %s", esErrorString(err)) } return nil @@ -124,7 +124,7 @@ func CcrFollowerUnfollow(conf *cfg.Config, index string) error { _, err := create.Do(context.Background()) if err != nil { - return fmt.Errorf("failed to unfollow index: %s", err) + return fmt.Errorf("failed to unfollow index: %s", esErrorString(err)) } return nil @@ -149,7 +149,7 @@ func CcrFollowerAdd(conf *cfg.Config, index string) error { _, err = create.Do(context.Background()) if err != nil { - return fmt.Errorf("failed to create follower index: %s", err) + return fmt.Errorf("failed to create follower index: %s", esErrorString(err)) } return nil @@ -161,7 +161,7 @@ func CcrFollowerShow(conf *cfg.Config, index string) error { Header("accept", "application/json"). Do(context.Background()) if err != nil { - return fmt.Errorf("failed to retrieve follower index info: %s", err) + return fmt.Errorf("failed to retrieve follower index info: %s", esErrorString(err)) } slog.Debug("ES result", "follower stats", res.Indices) diff --git a/pkg/es/cluster_settings.go b/pkg/es/cluster_settings.go index 48af363..e27fb91 100644 --- a/pkg/es/cluster_settings.go +++ b/pkg/es/cluster_settings.go @@ -23,7 +23,7 @@ import ( "log/slog" "codeberg.org/scip/esctl/pkg/cfg" - "codeberg.org/scip/esctl/pkg/printer" + "codeberg.org/scip/esctl/pkg/printer" "github.com/urfave/cli/v3" ) @@ -63,7 +63,7 @@ func ClusterSettingsList(conf *cfg.Config) error { Header("accept", "application/json"). Do(context.Background()) if err != nil { - return fmt.Errorf("failed to get cluster settings: %s", err) + return fmt.Errorf("failed to get cluster settings: %s", esErrorString(err)) } table := printer.NewTable(conf, 2, 0) @@ -135,7 +135,7 @@ func ClusterSettingsSet(conf *cfg.Config, args cli.Args) error { Do(context.Background()) if err != nil { - return fmt.Errorf("failed to set settings: %s", err) + return fmt.Errorf("failed to set settings: %s", esErrorString(err)) } return nil @@ -154,7 +154,7 @@ func ClusterSettingsSetSingle(conf *cfg.Config, setting, value string) error { Do(context.Background()) if err != nil { - return fmt.Errorf("failed to set %s: %s", setting, err) + return fmt.Errorf("failed to set %s: %s", setting, esErrorString(err)) } return nil diff --git a/pkg/es/cluster_util.go b/pkg/es/cluster_util.go index b4ac306..019920c 100644 --- a/pkg/es/cluster_util.go +++ b/pkg/es/cluster_util.go @@ -41,7 +41,7 @@ func checkClusterIsLeader(conf *cfg.Config, leader string) bool { Header("accept", "application/json"). Do(context.Background()) if err != nil { - fmt.Printf("failed to get ccr stats from %s: %s", leader, err) + fmt.Printf("failed to get ccr stats from %s: %s", leader, esErrorString(err)) return false } @@ -68,7 +68,7 @@ func checkClusterStatus(conf *cfg.Config, leader, follower string) bool { Header("accept", "application/json"). Do(context.Background()) if err != nil { - fmt.Printf("failed to get health from %s: %s", cluster, err) + fmt.Printf("failed to get health from %s: %s", cluster, esErrorString(err)) return false } @@ -128,7 +128,7 @@ func findIlmErrors(conf *cfg.Config, leader, follower string) bool { Header("accept", "application/json"). Do(context.Background()) if err != nil { - fmt.Printf("failed to get ilm status from %s: %s", cluster, err) + fmt.Printf("failed to get ilm status from %s: %s", cluster, esErrorString(err)) return false } diff --git a/pkg/es/doc.go b/pkg/es/doc.go index 58d203e..6daf4b3 100644 --- a/pkg/es/doc.go +++ b/pkg/es/doc.go @@ -53,7 +53,7 @@ func DocAdd(conf *cfg.Config, jsondoc string) error { Header("accept", "application/json"). Do(context.Background()) if err != nil { - return fmt.Errorf("failed to create new doc in index %s: %s", conf.Index, err) + return fmt.Errorf("failed to create new doc in index %s: %s", conf.Index, esErrorString(err)) } fmt.Println(res.Id_) @@ -67,7 +67,7 @@ func DocShow(conf *cfg.Config, id string) error { Header("accept", "application/json"). Do(context.Background()) if err != nil { - return fmt.Errorf("failed to retrieve doc in index %s: %s", conf.Index, err) + return fmt.Errorf("failed to retrieve doc in index %s: %s", conf.Index, esErrorString(err)) } if !res.Found { @@ -100,7 +100,7 @@ func DocDelete(conf *cfg.Config, queries []string) error { Header("accept", "application/json"). Do(context.Background()) if err != nil { - return fmt.Errorf("failed to delete doc in index %s: %s", conf.Index, err) + return fmt.Errorf("failed to delete doc in index %s: %s", conf.Index, esErrorString(err)) } return nil @@ -125,7 +125,7 @@ func DocDelete(conf *cfg.Config, queries []string) error { Header("accept", "application/json"). Do(context.Background()) if err != nil { - return fmt.Errorf("failed to delete docs in index %s: %s", conf.Index, err) + return fmt.Errorf("failed to delete docs in index %s: %s", conf.Index, esErrorString(err)) } return nil diff --git a/pkg/es/errors.go b/pkg/es/errors.go new file mode 100644 index 0000000..6da6ae9 --- /dev/null +++ b/pkg/es/errors.go @@ -0,0 +1,40 @@ +/* +Copyright © 2026 Thomas von Dein + +This program is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program. If not, see . +*/ +package es + +import ( + "fmt" + + "github.com/elastic/go-elasticsearch/v9/typedapi/types" +) + +func esErrorString(err error) string { + msg := err.Error() + + switch e := err.(type) { + case *types.ElasticsearchError: + causes := "" + + for _, cause := range e.ErrorCause.RootCause { + causes += fmt.Sprintf("%s\n", *cause.Reason) + } + + msg = *e.ErrorCause.Reason + ": " + causes + } + + return msg +} diff --git a/pkg/es/index.go b/pkg/es/index.go index ed5e589..26e4028 100644 --- a/pkg/es/index.go +++ b/pkg/es/index.go @@ -40,7 +40,7 @@ func IndexNames(conf *cfg.Config) ([]string, error) { Do(context.Background()) if err != nil { - return nil, fmt.Errorf("failed to get indicies: %s", err) + return nil, fmt.Errorf("failed to get indicies: %s", esErrorString(err)) } indices := make([]string, len(res)) @@ -81,7 +81,7 @@ func IndexList(conf *cfg.Config) error { res, err := cat.Do(context.Background()) if err != nil { - return fmt.Errorf("failed to get indicies: %s", err) + return fmt.Errorf("failed to get indicies: %s", esErrorString(err)) } slog.Debug("ES result", "indicies", res) @@ -124,7 +124,7 @@ func IndexShow(conf *cfg.Config, index string) error { Header("accept", "application/json"). Do(context.Background()) if err != nil { - return fmt.Errorf("failed to get index: %s", err) + return fmt.Errorf("failed to get index: %s", esErrorString(err)) } slog.Debug("ES result", "index", res) @@ -208,7 +208,7 @@ func IndexCreate(conf *cfg.Config, index string, mappings []string) error { Do(context.Background()) if err != nil { - return fmt.Errorf("failed to create index: %s", err) + return fmt.Errorf("failed to create index: %s", esErrorString(err)) } return nil @@ -220,7 +220,7 @@ func IndexDelete(conf *cfg.Config, index string) error { Header("accept", "application/json"). Do(context.Background()) if err != nil { - return fmt.Errorf("failed to delete index: %s", err) + return fmt.Errorf("failed to delete index: %s", esErrorString(err)) } return nil @@ -234,7 +234,7 @@ func IndexClose(conf *cfg.Config, index string) error { _, err := create.Do(context.Background()) if err != nil { - return fmt.Errorf("failed to close index: %s", err) + return fmt.Errorf("failed to close index: %s", esErrorString(err)) } return nil @@ -249,7 +249,7 @@ func IndexAllocation(conf *cfg.Config, index string) error { Header("accept", "application/json"). Do(context.Background()) if err != nil { - return fmt.Errorf("failed to get index allocation explain: %s", err) + return fmt.Errorf("failed to get index allocation explain: %s", esErrorString(err)) } slog.Debug("ES result", "index", res) @@ -294,7 +294,44 @@ func IndexModify(conf *cfg.Config, index string) error { Header("accept", "application/json"). Do(context.Background()) if err != nil { - return fmt.Errorf("failed to modify index settings: %s", err) + return fmt.Errorf("failed to modify index settings: %s", esErrorString(err)) + } + + return nil +} + +func IndexFields(conf *cfg.Config, index string) error { + res, err := conf.DefaultCluster.ES.FieldCaps(). + Index(index). + Fields("*"). + Header("content-type", "application/json"). + Header("accept", "application/json"). + Do(context.Background()) + if err != nil { + return fmt.Errorf("failed to retrieve field capabilties: %s", esErrorString(err)) + } + + table := printer.NewTable(conf, 5, len(res.Fields)) + table.Addheaders("field", "type", "searchable", "aggretable", "metadata") + + idx := 0 + for name, field := range res.Fields { + for fieldtype, caps := range field { + // fields only have 1 type, so this one is it + table.Entries[idx] = []string{name, fieldtype, + fmt.Sprintf("%t", caps.Searchable), + fmt.Sprintf("%t", caps.Aggregatable), + fmt.Sprintf("%t", *caps.MetadataField)} + break + } + + idx++ + } + + table.Sort() + + if err := table.Print(); err != nil { + return err } return nil diff --git a/pkg/es/index_alias.go b/pkg/es/index_alias.go index 06ec477..e29476f 100644 --- a/pkg/es/index_alias.go +++ b/pkg/es/index_alias.go @@ -37,7 +37,7 @@ func IndexAliasCreate(conf *cfg.Config, index, alias string) error { slog.Debug("create alias", "result", res) if err != nil { - return fmt.Errorf("failed to create index alias: %s", err) + return fmt.Errorf("failed to create index alias: %s", esErrorString(err)) } return nil @@ -58,7 +58,7 @@ func IndexAliasList(conf *cfg.Config) error { Do(context.Background()) if err != nil { - return fmt.Errorf("failed to list index aliases: %s", err) + return fmt.Errorf("failed to list index aliases: %s", esErrorString(err)) } slog.Debug("aliases list", "result", res) @@ -108,7 +108,7 @@ func IndexAliasDelete(conf *cfg.Config, index, alias string) error { slog.Debug("delete alias", "result", res) if err != nil { - return fmt.Errorf("failed to delete index alias: %s", err) + return fmt.Errorf("failed to delete index alias: %s", esErrorString(err)) } return nil diff --git a/pkg/es/node.go b/pkg/es/node.go index d5c9ff4..2676c79 100644 --- a/pkg/es/node.go +++ b/pkg/es/node.go @@ -22,14 +22,14 @@ import ( "log/slog" "codeberg.org/scip/esctl/pkg/cfg" - "codeberg.org/scip/esctl/pkg/printer" + "codeberg.org/scip/esctl/pkg/printer" ) func NodeList(conf *cfg.Config) error { // get nodes nodes, err := conf.DefaultCluster.ES.Cat.Nodes().Do(context.Background()) if err != nil { - return fmt.Errorf("failed to get nodes: %s", err) + return fmt.Errorf("failed to get nodes: %s", esErrorString(err)) } slog.Debug("ES result", "nodes", nodes) diff --git a/pkg/es/repl.go b/pkg/es/repl.go index c3b357d..ab30120 100644 --- a/pkg/es/repl.go +++ b/pkg/es/repl.go @@ -112,7 +112,7 @@ func Repl(conf *cfg.Config) error { err = CallAPI(conf, parts[0], parts[1], data) if err != nil { - fmt.Printf("failed to call API: %s\n", err) + fmt.Printf("failed to call API: %s\n", esErrorString(err)) } reader.SetPrompt("> ") diff --git a/pkg/es/search.go b/pkg/es/search.go index b82d849..9711c92 100644 --- a/pkg/es/search.go +++ b/pkg/es/search.go @@ -21,7 +21,6 @@ import ( "fmt" "log" "log/slog" - "strings" "time" "codeberg.org/scip/esctl/pkg/cfg" @@ -56,18 +55,18 @@ func Search(conf *cfg.Config, queries []string) error { searchEs.Request(req) + searchEs = addSort(conf, searchEs) + switch conf.Tail { case true: return searchTail(conf, searchEs) - case false: + default: if conf.To > MAXPAGE { return searchPit(conf, req) } else { return searchOnce(conf, searchEs) } } - - return nil } func Debug(conf *cfg.Config) error { @@ -95,11 +94,7 @@ func searchOnce(conf *cfg.Config, search *search.Search) error { Size(conf.To). Do(context.Background()) if err != nil { - if strings.Contains(err.Error(), "reason: all shards failed") { - return nil - } - - return fmt.Errorf("failed to run search (esdsl): %s", err) + return fmt.Errorf("failed to run search (esdsl): %s", esErrorString(err)) } slog.Debug("ES result", "search", res) @@ -134,14 +129,12 @@ func searchPit(conf *cfg.Config, req *search.Request) error { AddSortOption("_shard_doc", esdsl.NewFieldSort(sortorder.Asc))). Size(conf.To) + search = addSort(conf, search) + for { res, err := search.Do(ctx) if err != nil { - if strings.Contains(err.Error(), "reason: all shards failed") { - return nil - } - - return fmt.Errorf("failed to run search (esdsl pit): %s", err) + return fmt.Errorf("failed to run search (esdsl pit): %s", esErrorString(err)) } if len(res.Hits.Hits) == 0 { @@ -173,11 +166,7 @@ func searchTail(conf *cfg.Config, search *search.Search) error { for { res, err := search.Do(context.Background()) if err != nil { - if strings.Contains(err.Error(), "reason: all shards failed") { - return nil - } - - return fmt.Errorf("failed to run search (esdsl): %s", err) + return fmt.Errorf("failed to run search (esdsl): %s", esErrorString(err)) } slog.Debug("ES result", "search", res) diff --git a/pkg/es/search_filter.go b/pkg/es/search_filter.go index 8cdb895..f992a19 100644 --- a/pkg/es/search_filter.go +++ b/pkg/es/search_filter.go @@ -17,15 +17,18 @@ along with this program. If not, see . package es import ( + "context" "errors" "fmt" "log/slog" "strings" "codeberg.org/scip/esctl/pkg/cfg" + "github.com/elastic/go-elasticsearch/v9/typedapi/core/search" "github.com/elastic/go-elasticsearch/v9/typedapi/esdsl" "github.com/elastic/go-elasticsearch/v9/typedapi/types" "github.com/elastic/go-elasticsearch/v9/typedapi/types/enums/operator" + "github.com/elastic/go-elasticsearch/v9/typedapi/types/enums/sortorder" ) const ( @@ -236,3 +239,42 @@ func addFilters(conf *cfg.Config) ([]types.QueryVariant, error) { return filters, nil } + +// check if the conf.SortBy field (default: @timestamp) is searchable +// by using the field capabilities API. +func addSort(conf *cfg.Config, search *search.Search) *search.Search { + res, err := conf.DefaultCluster.ES.FieldCaps(). + Index(conf.Index). + Fields(conf.SortBy). + Do(context.Background()) + + if err != nil { + // whatever it was, do not add Sort() + slog.Debug("get field capabilities", "field", conf.SortBy, "error", esErrorString(err)) + + return search + } + + field, exists := res.Fields[conf.SortBy] + + if exists { + // good, the field exists + for _, cap := range field { + if cap.Searchable { + // ok, ES would be willing to sort by this field + order := esdsl.NewFieldSort(sortorder.Desc) + if conf.Ascending { + order = esdsl.NewFieldSort(sortorder.Asc) + } + + search = search.Sort( + esdsl.NewSortOptions().AddSortOption(conf.SortBy, order), + ) + + break + } + } + } + + return search +} diff --git a/pkg/es/shard.go b/pkg/es/shard.go index 897e292..2addb71 100644 --- a/pkg/es/shard.go +++ b/pkg/es/shard.go @@ -88,7 +88,7 @@ func ShardList(conf *cfg.Config) error { Header("accept", "application/json"). Do(context.Background()) if err != nil { - return fmt.Errorf("failed to get shards: %s", err) + return fmt.Errorf("failed to get shards: %s", esErrorString(err)) } shardlist := filterShards(conf, res) @@ -140,7 +140,7 @@ func ShardShow(conf *cfg.Config, index string) error { Header("accept", "application/json"). Do(context.Background()) if err != nil { - return fmt.Errorf("failed to get shards: %s", err) + return fmt.Errorf("failed to get shards: %s", esErrorString(err)) } slog.Debug("ES result", "shards", res) diff --git a/pkg/es/snapshot.go b/pkg/es/snapshot.go index 658b9fa..78c10df 100644 --- a/pkg/es/snapshot.go +++ b/pkg/es/snapshot.go @@ -25,7 +25,7 @@ import ( "strings" "codeberg.org/scip/esctl/pkg/cfg" - "codeberg.org/scip/esctl/pkg/printer" + "codeberg.org/scip/esctl/pkg/printer" ) var ( @@ -45,7 +45,7 @@ func SnapshotList(conf *cfg.Config) error { // get partial indicies ires, err := conf.DefaultCluster.ES.Cat.Indices().Do(context.Background()) if err != nil { - return fmt.Errorf("failed to get indicies: %s", err) + return fmt.Errorf("failed to get indicies: %s", esErrorString(err)) } indicies := map[string]int{} @@ -58,7 +58,7 @@ func SnapshotList(conf *cfg.Config) error { // get snapshots sres, err := conf.DefaultCluster.ES.Cat.Snapshots().Do(context.Background()) if err != nil { - return fmt.Errorf("failed to get snapshots: %s", err) + return fmt.Errorf("failed to get snapshots: %s", esErrorString(err)) } slog.Debug("ES result", "indicies", sres) @@ -108,7 +108,7 @@ func SnapshotList(conf *cfg.Config) error { func SnapshotShow(conf *cfg.Config, snapshot string) error { res, err := conf.DefaultCluster.ES.Snapshot.Get("*", snapshot).Do(context.Background()) if err != nil { - return fmt.Errorf("failed to get snapshot: %s", err) + return fmt.Errorf("failed to get snapshot: %s", esErrorString(err)) } slog.Debug("ES result", "snapshot", res)