mirror of
https://codeberg.org/scip/esctl.git
synced 2026-08-24 21:44:19 +02:00
same thing with index ls
This commit is contained in:
@@ -30,9 +30,11 @@ import (
|
||||
|
||||
"codeberg.org/scip/esctl/pkg/cfg"
|
||||
"codeberg.org/scip/esctl/pkg/printer"
|
||||
"codeberg.org/scip/mapmap"
|
||||
"github.com/charmbracelet/lipgloss"
|
||||
"github.com/elastic/go-elasticsearch/v9/typedapi/cat/indices"
|
||||
"github.com/elastic/go-elasticsearch/v9/typedapi/esdsl"
|
||||
"github.com/elastic/go-elasticsearch/v9/typedapi/types"
|
||||
"github.com/elastic/go-elasticsearch/v9/typedapi/types/enums/healthstatus"
|
||||
)
|
||||
|
||||
@@ -53,41 +55,35 @@ func IndexNames(conf *cfg.Config) ([]string, error) {
|
||||
}
|
||||
|
||||
func filterIndices(conf *cfg.Config, list indices.Response) indices.Response {
|
||||
// apply partials filter first
|
||||
selectedlist := indices.Response{}
|
||||
var filter *regexp.Regexp
|
||||
|
||||
if len(conf.Filter) > 0 {
|
||||
filter = regexp.MustCompile(conf.Filter[0])
|
||||
}
|
||||
|
||||
return mapmap.NewSlicer(list).MapSliceValuesImmutable(func(index types.IndicesRecord) bool {
|
||||
fmt.Println(*index.Index)
|
||||
if strings.HasPrefix(*index.Index, ".ds-") {
|
||||
// ignore data stream backing indicies
|
||||
return false
|
||||
}
|
||||
|
||||
for _, index := range list {
|
||||
if !conf.Partials && strings.HasPrefix(*index.Index, "partial-") {
|
||||
continue
|
||||
return false
|
||||
}
|
||||
|
||||
if !conf.Hidden && strings.HasPrefix(*index.Index, ".") {
|
||||
continue
|
||||
return false
|
||||
}
|
||||
|
||||
if strings.HasPrefix(*index.Index, ".ds-") {
|
||||
// ignore data stream backing indicies
|
||||
continue
|
||||
if len(conf.Filter) > 0 {
|
||||
if !filter.MatchString(*index.Index) {
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
selectedlist = append(selectedlist, index)
|
||||
}
|
||||
|
||||
if len(conf.Filter) == 0 {
|
||||
return selectedlist
|
||||
}
|
||||
|
||||
// we support just one filter here, for now
|
||||
filter := *regexp.MustCompile(conf.Filter[0])
|
||||
newlist := indices.Response{}
|
||||
|
||||
for _, index := range selectedlist {
|
||||
if filter.MatchString(*index.Index) {
|
||||
newlist = append(newlist, index)
|
||||
}
|
||||
}
|
||||
|
||||
return newlist
|
||||
return true
|
||||
})
|
||||
}
|
||||
|
||||
func IndexList(conf *cfg.Config) error {
|
||||
|
||||
Reference in New Issue
Block a user