mirror of
https://codeberg.org/scip/esctl.git
synced 2026-08-24 16:24:19 +02:00
add index fields filter flags (#27)
This commit is contained in:
21
cmd/index.go
21
cmd/index.go
@@ -260,6 +260,27 @@ func IndexFields(conf *cfg.Config) *cli.Command {
|
|||||||
Usage: "show info about field capabilities",
|
Usage: "show info about field capabilities",
|
||||||
UsageText: "index fields <index>",
|
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 {
|
Action: func(ctx context.Context, cmd *cli.Command) error {
|
||||||
index := cmd.Args().Get(0)
|
index := cmd.Args().Get(0)
|
||||||
if index == "" {
|
if index == "" {
|
||||||
|
|||||||
@@ -34,7 +34,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
Version string = `v0.0.16`
|
Version string = `v0.0.17`
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
@@ -59,6 +59,8 @@ type Config struct {
|
|||||||
Shards, Replicas int // index create+allocation: -s -r
|
Shards, Replicas int // index create+allocation: -s -r
|
||||||
Wait bool // index create: -w
|
Wait bool // index create: -w
|
||||||
Primary bool // index allocation: -p
|
Primary bool // index allocation: -p
|
||||||
|
Searchable bool // index fields: -s
|
||||||
|
Aggretable bool // index fields: -a
|
||||||
From, To, MaxItems int // search: flags
|
From, To, MaxItems int // search: flags
|
||||||
Filter []string // search: -F
|
Filter []string // search: -F
|
||||||
Path string // search+doc sh: -p
|
Path string // search+doc sh: -p
|
||||||
|
|||||||
@@ -21,6 +21,7 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"log/slog"
|
"log/slog"
|
||||||
"regexp"
|
"regexp"
|
||||||
|
"slices"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
@@ -311,17 +312,26 @@ func IndexFields(conf *cfg.Config, index string) error {
|
|||||||
return fmt.Errorf("failed to retrieve field capabilties: %s", esErrorString(err))
|
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")
|
table.Addheaders("field", "type", "searchable", "aggretable", "metadata")
|
||||||
|
|
||||||
idx := 0
|
idx := 0
|
||||||
for name, field := range res.Fields {
|
for name, field := range res.Fields {
|
||||||
for fieldtype, caps := range field {
|
for fieldtype, caps := range field {
|
||||||
// fields only have 1 type, so this one is it
|
// 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.Searchable),
|
||||||
fmt.Sprintf("%t", caps.Aggregatable),
|
fmt.Sprintf("%t", caps.Aggregatable),
|
||||||
fmt.Sprintf("%t", *caps.MetadataField)}
|
fmt.Sprintf("%t", *caps.MetadataField)})
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user