mirror of
https://codeberg.org/scip/esctl.git
synced 2026-08-24 09:54:18 +02:00
add doc delete (#23)
This commit is contained in:
65
cmd/doc.go
65
cmd/doc.go
@@ -34,7 +34,7 @@ func Doc(conf *cfg.Config) *cli.Command {
|
||||
Commands: []*cli.Command{
|
||||
DocAdd(conf),
|
||||
DocShow(conf),
|
||||
//Delete(conf),
|
||||
DocDelete(conf),
|
||||
},
|
||||
}
|
||||
}
|
||||
@@ -112,3 +112,66 @@ func DocShow(conf *cfg.Config) *cli.Command {
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
func DocDelete(conf *cfg.Config) *cli.Command {
|
||||
return &cli.Command{
|
||||
Name: "delete",
|
||||
Aliases: []string{"rm"},
|
||||
Usage: "delete JSON document[s] from index[es]",
|
||||
UsageText: "delete [options] -i <index> [<[field<sep>]pattern> ...]\n" + SearchUsage,
|
||||
|
||||
Flags: []cli.Flag{
|
||||
&cli.BoolFlag{
|
||||
Name: "all",
|
||||
Usage: "delete all docs (dangerous!)",
|
||||
Destination: &conf.All,
|
||||
Aliases: []string{"a"},
|
||||
},
|
||||
&cli.StringFlag{
|
||||
Name: "index",
|
||||
Usage: "index to work on",
|
||||
Sources: cli.EnvVars("ES_INDEX"),
|
||||
Destination: &conf.Index,
|
||||
Aliases: []string{"i"},
|
||||
},
|
||||
&cli.StringSliceFlag{
|
||||
Name: "filter",
|
||||
Usage: "additional boolean filters. format: key=value",
|
||||
Destination: &conf.Filter,
|
||||
Aliases: []string{"F"},
|
||||
},
|
||||
&cli.StringFlag{
|
||||
Name: "timerange",
|
||||
Usage: "field:<date> to <date> (e.g. @timestamp:2026-05-05 to 2026-05-15)",
|
||||
Destination: &conf.Range,
|
||||
Aliases: []string{"r"},
|
||||
},
|
||||
&cli.StringFlag{
|
||||
Name: "timestamp-format",
|
||||
Usage: "a valid ES builtin timestamp or custom format",
|
||||
Destination: &conf.TimestampFormat,
|
||||
Value: "strict_date_hour_minute",
|
||||
},
|
||||
&cli.BoolFlag{
|
||||
Name: "or",
|
||||
Usage: "logical operator (default: and)",
|
||||
Destination: &conf.Or,
|
||||
Aliases: []string{"O"},
|
||||
},
|
||||
},
|
||||
|
||||
Action: func(ctx context.Context, cmd *cli.Command) error {
|
||||
if conf.Subhelp {
|
||||
return showJsonPathHelp()
|
||||
}
|
||||
|
||||
args := cmd.Args()
|
||||
|
||||
if args.Len() == 0 && !conf.All {
|
||||
return errors.New("missing arguments: <query>")
|
||||
}
|
||||
|
||||
return es.DocDelete(conf, cmd.Args().Slice())
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
@@ -26,14 +26,7 @@ import (
|
||||
"github.com/urfave/cli/v3"
|
||||
)
|
||||
|
||||
func Search(conf *cfg.Config) *cli.Command {
|
||||
return &cli.Command{
|
||||
Name: "search",
|
||||
Aliases: []string{"/"},
|
||||
Usage: "search within an index",
|
||||
UsageText: `search [options] [<[field<sep>]pattern> ...]
|
||||
|
||||
<sep> might be one of:
|
||||
const SearchUsage = `<sep> might be one of:
|
||||
=: Must match
|
||||
!=: Must not match
|
||||
|
||||
@@ -52,7 +45,14 @@ 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
|
||||
`,
|
||||
`
|
||||
|
||||
func Search(conf *cfg.Config) *cli.Command {
|
||||
return &cli.Command{
|
||||
Name: "search",
|
||||
Aliases: []string{"/"},
|
||||
Usage: "search within an index",
|
||||
UsageText: "search [options] [<[field<sep>]pattern> ...]\n" + SearchUsage,
|
||||
|
||||
Flags: []cli.Flag{
|
||||
&cli.StringFlag{
|
||||
|
||||
Reference in New Issue
Block a user