mirror of
https://codeberg.org/scip/esctl.git
synced 2026-08-24 22:44:17 +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/cfg"
|
||||||
"codeberg.org/scip/esctl/pkg/printer"
|
"codeberg.org/scip/esctl/pkg/printer"
|
||||||
|
"codeberg.org/scip/mapmap"
|
||||||
"github.com/charmbracelet/lipgloss"
|
"github.com/charmbracelet/lipgloss"
|
||||||
"github.com/elastic/go-elasticsearch/v9/typedapi/cat/indices"
|
"github.com/elastic/go-elasticsearch/v9/typedapi/cat/indices"
|
||||||
"github.com/elastic/go-elasticsearch/v9/typedapi/esdsl"
|
"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"
|
"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 {
|
func filterIndices(conf *cfg.Config, list indices.Response) indices.Response {
|
||||||
// apply partials filter first
|
var filter *regexp.Regexp
|
||||||
selectedlist := indices.Response{}
|
|
||||||
|
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-") {
|
if !conf.Partials && strings.HasPrefix(*index.Index, "partial-") {
|
||||||
continue
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
if !conf.Hidden && strings.HasPrefix(*index.Index, ".") {
|
if !conf.Hidden && strings.HasPrefix(*index.Index, ".") {
|
||||||
continue
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
if strings.HasPrefix(*index.Index, ".ds-") {
|
if len(conf.Filter) > 0 {
|
||||||
// ignore data stream backing indicies
|
if !filter.MatchString(*index.Index) {
|
||||||
continue
|
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 {
|
func IndexList(conf *cfg.Config) error {
|
||||||
|
|||||||
Reference in New Issue
Block a user