add index fields filter flags (#27)

This commit is contained in:
T. von Dein
2026-06-03 10:14:41 +02:00
parent 18af1b6073
commit 5ecba5abe6
3 changed files with 37 additions and 4 deletions

View File

@@ -260,6 +260,27 @@ func IndexFields(conf *cfg.Config) *cli.Command {
Usage: "show info about field capabilities",
UsageText: "index fields <index>",
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 == "" {

View File

@@ -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

View File

@@ -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
}