diff --git a/cmd/index.go b/cmd/index.go index 2fae152..5579f7d 100644 --- a/cmd/index.go +++ b/cmd/index.go @@ -260,6 +260,27 @@ func IndexFields(conf *cfg.Config) *cli.Command { Usage: "show info about field capabilities", UsageText: "index fields ", + Flags: []cli.Flag{ + &cli.BoolFlag{ + Name: "aggretable", + Usage: "include only aggretable fields", + Destination: &conf.Aggretable, + Aliases: []string{"a"}, + }, + &cli.BoolFlag{ + Name: "searchable", + Usage: "include only searchable fields", + Destination: &conf.Searchable, + Aliases: []string{"s"}, + }, + &cli.StringSliceFlag{ + Name: "type", + Usage: "show only fields of this type", + Destination: &conf.Filter, + Aliases: []string{"t"}, + }, + }, + Action: func(ctx context.Context, cmd *cli.Command) error { index := cmd.Args().Get(0) if index == "" { diff --git a/pkg/cfg/config.go b/pkg/cfg/config.go index 31dd365..1cd2a94 100644 --- a/pkg/cfg/config.go +++ b/pkg/cfg/config.go @@ -34,7 +34,7 @@ import ( ) const ( - Version string = `v0.0.16` + Version string = `v0.0.17` ) var ( @@ -59,6 +59,8 @@ type Config struct { Shards, Replicas int // index create+allocation: -s -r Wait bool // index create: -w Primary bool // index allocation: -p + Searchable bool // index fields: -s + Aggretable bool // index fields: -a From, To, MaxItems int // search: flags Filter []string // search: -F Path string // search+doc sh: -p diff --git a/pkg/es/index.go b/pkg/es/index.go index 26e4028..e2877b3 100644 --- a/pkg/es/index.go +++ b/pkg/es/index.go @@ -21,6 +21,7 @@ import ( "fmt" "log/slog" "regexp" + "slices" "strconv" "strings" "time" @@ -311,17 +312,26 @@ func IndexFields(conf *cfg.Config, index string) error { return fmt.Errorf("failed to retrieve field capabilties: %s", esErrorString(err)) } - table := printer.NewTable(conf, 5, len(res.Fields)) + table := printer.NewTable(conf, 5, 0) table.Addheaders("field", "type", "searchable", "aggretable", "metadata") idx := 0 for name, field := range res.Fields { for fieldtype, caps := range field { // fields only have 1 type, so this one is it - table.Entries[idx] = []string{name, fieldtype, + switch { + case conf.Searchable && !caps.Searchable: + continue + case conf.Aggretable && !caps.Aggregatable: + continue + case len(conf.Filter) > 0 && !slices.Contains(conf.Filter, fieldtype): + continue + } + + table.Entries = append(table.Entries, []string{name, fieldtype, fmt.Sprintf("%t", caps.Searchable), fmt.Sprintf("%t", caps.Aggregatable), - fmt.Sprintf("%t", *caps.MetadataField)} + fmt.Sprintf("%t", *caps.MetadataField)}) break }