add feature esql search (#90)

This commit is contained in:
T. von Dein
2026-07-10 15:07:57 +02:00
parent 15dbf7ada0
commit f61fda0697
7 changed files with 1118 additions and 5 deletions

View File

@@ -24,10 +24,13 @@ import (
"runtime/pprof"
"strings"
"codeberg.org/scip/esctl/assets"
"codeberg.org/scip/esctl/pkg/cfg"
"codeberg.org/scip/esctl/pkg/es"
"codeberg.org/scip/esctl/pkg/log"
"codeberg.org/scip/esctl/pkg/printer"
markdown "github.com/MichaelMure/go-term-markdown"
"github.com/urfave/cli/v3"
)
@@ -141,7 +144,7 @@ func Main() int {
Name: "output",
Aliases: []string{"o"},
Value: "",
Usage: "output mode (tsv, json, yaml) default: tsv",
Usage: "output mode (tsv, csv, json, yaml) default: tsv",
Destination: &conf.Output,
},
&cli.StringFlag{
@@ -164,6 +167,7 @@ func Main() int {
Node(conf),
Roles(conf),
Search(conf),
SearchQL(conf),
Shard(conf),
Snapshot(conf),
Task(conf),
@@ -171,6 +175,7 @@ func Main() int {
Debug(conf),
HelpJsonPath(conf),
HelpUsage(conf),
HelpEsQl(conf),
},
Before: func(ctx context.Context, cmd *cli.Command) (context.Context, error) {
@@ -226,6 +231,22 @@ func HelpJsonPath(conf *cfg.Config) *cli.Command {
}
}
func HelpEsQl(conf *cfg.Config) *cli.Command {
return &cli.Command{
Name: "help-esql",
Usage: "show esql help",
Action: func(ctx context.Context, cmd *cli.Command) error {
assets.LoadEsql()
width := cfg.GetTermWidth()
printer.Pager("esql cheat sheet", string(markdown.Render(assets.EsQlCheatSheet, width, cfg.DefaultMargin)))
return nil
},
}
}
func Version(conf *cfg.Config) *cli.Command {
return &cli.Command{
Name: "version",

View File

@@ -18,6 +18,7 @@ package cmd
import (
"context"
"strings"
"codeberg.org/scip/esctl/pkg/cfg"
"codeberg.org/scip/esctl/pkg/es"
@@ -45,6 +46,11 @@ https://www.elastic.co/docs/reference/elasticsearch/rest-apis/common-options#dat
For timestamp formats refer to:
https://www.elastic.co/docs/reference/elasticsearch/mapping-reference/mapping-date-format`
const QlUsage = `ES|QL documentation:
https://www.elastic.co/docs/reference/query-languages/esql/esql-getting-started
See also: esctl help-esql`
func Search(conf *cfg.Config) *cli.Command {
return &cli.Command{
Name: "search",
@@ -149,3 +155,19 @@ func Search(conf *cfg.Config) *cli.Command {
},
}
}
func SearchQL(conf *cfg.Config) *cli.Command {
return &cli.Command{
Name: "searchql",
Aliases: []string{"/"},
Usage: "search using ES/QL language",
UsageText: "search <ES/QL term>",
CustomHelpTemplate: addReference(QlUsage),
Action: func(ctx context.Context, cmd *cli.Command) error {
args := cmd.Args()
return es.SearchQL(conf, strings.Join(args.Slice(), " "))
},
}
}