mirror of
https://codeberg.org/scip/esctl.git
synced 2026-08-24 08:14:18 +02:00
add sort support to search, add index fields command, fix error messages (#25)
This commit is contained in:
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user