mirror of
https://codeberg.org/scip/esctl.git
synced 2026-08-24 10:04: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,
|
Destination: &conf.Path,
|
||||||
Aliases: []string{"p"},
|
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 {
|
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",
|
Usage: "output mode (tsv, markdown, json, yaml) default: tsv",
|
||||||
Destination: &conf.Output,
|
Destination: &conf.Output,
|
||||||
},
|
},
|
||||||
|
&cli.BoolFlag{
|
||||||
|
Name: "help-jsonpath",
|
||||||
|
Usage: "show jsonPath help",
|
||||||
|
Destination: &conf.Subhelp,
|
||||||
|
Aliases: []string{"H"},
|
||||||
|
},
|
||||||
},
|
},
|
||||||
|
|
||||||
Commands: []*cli.Command{
|
Commands: []*cli.Command{
|
||||||
|
|||||||
@@ -113,12 +113,6 @@ func Search(conf *cfg.Config) *cli.Command {
|
|||||||
Destination: &conf.Ascending,
|
Destination: &conf.Ascending,
|
||||||
Aliases: []string{"a"},
|
Aliases: []string{"a"},
|
||||||
},
|
},
|
||||||
&cli.BoolFlag{
|
|
||||||
Name: "help-jsonpath",
|
|
||||||
Usage: "show jsonPath help",
|
|
||||||
Destination: &conf.Subhelp,
|
|
||||||
Aliases: []string{"H"},
|
|
||||||
},
|
|
||||||
&cli.BoolFlag{
|
&cli.BoolFlag{
|
||||||
Name: "tail",
|
Name: "tail",
|
||||||
Usage: "follow search live, like tail -f",
|
Usage: "follow search live, like tail -f",
|
||||||
|
|||||||
@@ -34,7 +34,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
Version string = `v0.0.17`
|
Version string = `v0.0.18`
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
|
|||||||
@@ -53,15 +53,24 @@ func IndexNames(conf *cfg.Config) ([]string, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func filterIndices(conf *cfg.Config, list indices.Response) indices.Response {
|
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 {
|
if len(conf.Filter) == 0 {
|
||||||
return list
|
return selectedlist
|
||||||
}
|
}
|
||||||
|
|
||||||
// we support just one filter here, for now
|
// we support just one filter here, for now
|
||||||
filter := *regexp.MustCompile(conf.Filter[0])
|
filter := *regexp.MustCompile(conf.Filter[0])
|
||||||
newlist := indices.Response{}
|
newlist := indices.Response{}
|
||||||
|
|
||||||
for _, index := range list {
|
for _, index := range selectedlist {
|
||||||
if filter.MatchString(*index.Index) {
|
if filter.MatchString(*index.Index) {
|
||||||
newlist = append(newlist, index)
|
newlist = append(newlist, index)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -99,9 +99,7 @@ func searchOnce(conf *cfg.Config, search *search.Search) error {
|
|||||||
|
|
||||||
slog.Debug("ES result", "search", res)
|
slog.Debug("ES result", "search", res)
|
||||||
|
|
||||||
for _, hit := range res.Hits.Hits {
|
printer.PrintDocs(conf, res.Hits.Hits)
|
||||||
printer.PrintDoc(conf, hit)
|
|
||||||
}
|
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
@@ -141,9 +139,7 @@ func searchPit(conf *cfg.Config, req *search.Request) error {
|
|||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, hit := range res.Hits.Hits {
|
printer.PrintDocs(conf, res.Hits.Hits)
|
||||||
printer.PrintDoc(conf, hit)
|
|
||||||
}
|
|
||||||
|
|
||||||
last := res.Hits.Hits[len(res.Hits.Hits)-1]
|
last := res.Hits.Hits[len(res.Hits.Hits)-1]
|
||||||
search = search.SearchAfterValues(last.Sort)
|
search = search.SearchAfterValues(last.Sort)
|
||||||
@@ -178,6 +174,7 @@ func searchTail(conf *cfg.Config, search *search.Search) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
printer.PrintDoc(conf, hit)
|
printer.PrintDoc(conf, hit)
|
||||||
|
fmt.Println()
|
||||||
|
|
||||||
docs[*hit.Id_] = 1
|
docs[*hit.Id_] = 1
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -18,12 +18,24 @@ package printer
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"slices"
|
||||||
|
|
||||||
"codeberg.org/scip/esctl/pkg/cfg"
|
"codeberg.org/scip/esctl/pkg/cfg"
|
||||||
"github.com/elastic/go-elasticsearch/v9/typedapi/types"
|
"github.com/elastic/go-elasticsearch/v9/typedapi/types"
|
||||||
"github.com/tidwall/gjson"
|
"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) {
|
func PrintDoc(conf *cfg.Config, hit types.Hit) {
|
||||||
var score types.Float64
|
var score types.Float64
|
||||||
if hit.Score_ != nil {
|
if hit.Score_ != nil {
|
||||||
@@ -40,6 +52,6 @@ func PrintDoc(conf *cfg.Config, hit types.Hit) {
|
|||||||
value := gjson.Get(docjson, conf.Path)
|
value := gjson.Get(docjson, conf.Path)
|
||||||
fmt.Println(value.String())
|
fmt.Println(value.String())
|
||||||
} else {
|
} else {
|
||||||
fmt.Println(docjson)
|
fmt.Print(docjson)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user