mirror of
https://codeberg.org/scip/esctl.git
synced 2026-08-24 09:34:17 +02:00
add index fields filter flags (#27)
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user