mirror of
https://codeberg.org/scip/esctl.git
synced 2026-08-24 03:34:18 +02:00
fix search output order (last on bottom) and index ls output partials (#30)
This commit is contained in:
@@ -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 {
|
||||
|
||||
@@ -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{
|
||||
|
||||
@@ -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",
|
||||
|
||||
@@ -34,7 +34,7 @@ import (
|
||||
)
|
||||
|
||||
const (
|
||||
Version string = `v0.0.17`
|
||||
Version string = `v0.0.18`
|
||||
)
|
||||
|
||||
var (
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user