diff --git a/cmd/doc.go b/cmd/doc.go index ee0bc0a..91b559e 100644 --- a/cmd/doc.go +++ b/cmd/doc.go @@ -89,12 +89,6 @@ func DocShow(conf *cfg.Config) *cli.Command { Destination: &conf.Path, Aliases: []string{"p"}, }, - &cli.BoolFlag{ - Name: "help-jsonpath", - Usage: "show jsonPath help", - Destination: &conf.Subhelp, - Aliases: []string{"H"}, - }, }, Action: func(ctx context.Context, cmd *cli.Command) error { diff --git a/cmd/root.go b/cmd/root.go index 0ec31d7..8882721 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -83,6 +83,12 @@ func Main() int { Usage: "output mode (tsv, markdown, json, yaml) default: tsv", Destination: &conf.Output, }, + &cli.BoolFlag{ + Name: "help-jsonpath", + Usage: "show jsonPath help", + Destination: &conf.Subhelp, + Aliases: []string{"H"}, + }, }, Commands: []*cli.Command{ diff --git a/cmd/search.go b/cmd/search.go index 435563f..3d68506 100644 --- a/cmd/search.go +++ b/cmd/search.go @@ -113,12 +113,6 @@ func Search(conf *cfg.Config) *cli.Command { Destination: &conf.Ascending, Aliases: []string{"a"}, }, - &cli.BoolFlag{ - Name: "help-jsonpath", - Usage: "show jsonPath help", - Destination: &conf.Subhelp, - Aliases: []string{"H"}, - }, &cli.BoolFlag{ Name: "tail", Usage: "follow search live, like tail -f", diff --git a/pkg/cfg/config.go b/pkg/cfg/config.go index 1cd2a94..381029e 100644 --- a/pkg/cfg/config.go +++ b/pkg/cfg/config.go @@ -34,7 +34,7 @@ import ( ) const ( - Version string = `v0.0.17` + Version string = `v0.0.18` ) var ( diff --git a/pkg/es/index.go b/pkg/es/index.go index dc9d48c..a1d329b 100644 --- a/pkg/es/index.go +++ b/pkg/es/index.go @@ -53,15 +53,24 @@ func IndexNames(conf *cfg.Config) ([]string, error) { } func filterIndices(conf *cfg.Config, list indices.Response) indices.Response { + // apply partials filter first + selectedlist := indices.Response{} + for _, index := range list { + if !conf.Partials && strings.HasPrefix(*index.Index, "partial-") { + continue + } + selectedlist = append(selectedlist, index) + } + if len(conf.Filter) == 0 { - return list + return selectedlist } // we support just one filter here, for now filter := *regexp.MustCompile(conf.Filter[0]) newlist := indices.Response{} - for _, index := range list { + for _, index := range selectedlist { if filter.MatchString(*index.Index) { newlist = append(newlist, index) } diff --git a/pkg/es/search.go b/pkg/es/search.go index 9711c92..8447af2 100644 --- a/pkg/es/search.go +++ b/pkg/es/search.go @@ -99,9 +99,7 @@ func searchOnce(conf *cfg.Config, search *search.Search) error { slog.Debug("ES result", "search", res) - for _, hit := range res.Hits.Hits { - printer.PrintDoc(conf, hit) - } + printer.PrintDocs(conf, res.Hits.Hits) return nil } @@ -141,9 +139,7 @@ func searchPit(conf *cfg.Config, req *search.Request) error { break } - for _, hit := range res.Hits.Hits { - printer.PrintDoc(conf, hit) - } + printer.PrintDocs(conf, res.Hits.Hits) last := res.Hits.Hits[len(res.Hits.Hits)-1] search = search.SearchAfterValues(last.Sort) @@ -178,6 +174,7 @@ func searchTail(conf *cfg.Config, search *search.Search) error { } printer.PrintDoc(conf, hit) + fmt.Println() docs[*hit.Id_] = 1 } diff --git a/pkg/printer/doc.go b/pkg/printer/doc.go index 00f8055..7b5a5e0 100644 --- a/pkg/printer/doc.go +++ b/pkg/printer/doc.go @@ -18,12 +18,24 @@ package printer import ( "fmt" + "slices" "codeberg.org/scip/esctl/pkg/cfg" "github.com/elastic/go-elasticsearch/v9/typedapi/types" "github.com/tidwall/gjson" ) +func PrintDocs(conf *cfg.Config, hits []types.Hit) { + if !conf.Ascending { + slices.Reverse(hits) + } + + for _, hit := range hits { + PrintDoc(conf, hit) + } + +} + func PrintDoc(conf *cfg.Config, hit types.Hit) { var score types.Float64 if hit.Score_ != nil { @@ -40,6 +52,6 @@ func PrintDoc(conf *cfg.Config, hit types.Hit) { value := gjson.Get(docjson, conf.Path) fmt.Println(value.String()) } else { - fmt.Println(docjson) + fmt.Print(docjson) } }