fix #49: add ilm policy to index+index-template create+modify (#50)

This commit is contained in:
T. von Dein
2026-06-25 07:52:54 +02:00
parent 75a94fade3
commit 825b3ce5d1
5 changed files with 64 additions and 43 deletions

View File

@@ -36,11 +36,11 @@ func Index(conf *cfg.Config) *cli.Command {
Commands: []*cli.Command{
IndexList(conf),
IndexShow(conf),
IndexCreate(conf),
IndexCreate(conf, false),
IndexCreate(conf, true),
IndexDelete(conf),
IndexClose(conf),
IndexAllocation(conf),
IndexModify(conf),
IndexFields(conf),
IndexIlm(conf),
@@ -143,12 +143,20 @@ func IndexShow(conf *cfg.Config) *cli.Command {
}
}
func IndexCreate(conf *cfg.Config) *cli.Command {
func IndexCreate(conf *cfg.Config, modify bool) *cli.Command {
name := "create"
usage := "create a new index"
if modify {
name = "modify"
usage = "modify anindex"
}
return &cli.Command{
Name: "create",
Name: name,
Aliases: []string{"+"},
Usage: "create a new index",
UsageText: `create <name> <fieldmapping:type>...
Usage: usage,
UsageText: name + ` <name> <fieldmapping:type>...
Valid field mapping types: integer, text, date, keyword`,
Flags: []cli.Flag{
@@ -171,6 +179,12 @@ Valid field mapping types: integer, text, date, keyword`,
Aliases: []string{"r"},
Value: 1,
},
&cli.StringFlag{
Name: "ilm-policy",
Usage: "ilm policy to apply",
Destination: &conf.Policy,
Aliases: []string{"p"},
},
},
Action: func(ctx context.Context, cmd *cli.Command) error {
@@ -229,37 +243,6 @@ func IndexClose(conf *cfg.Config) *cli.Command {
}
}
func IndexModify(conf *cfg.Config) *cli.Command {
return &cli.Command{
Name: "modify",
Usage: "modify an index",
UsageText: "modify <index[,index,...]|_all>",
ShellComplete: func(ctx context.Context, cmd *cli.Command) {
complete(cmd, Cindex)
},
Flags: []cli.Flag{
&cli.IntFlag{
Name: "replicas",
Usage: "number of replicas",
Destination: &conf.Replicas,
Aliases: []string{"r"},
Value: 1,
},
},
Action: func(ctx context.Context, cmd *cli.Command) error {
index := cmd.Args().Get(0)
if index == "" {
return errors.New("no index specified")
}
return es.IndexModify(conf, index)
},
}
}
func IndexFields(conf *cfg.Config) *cli.Command {
return &cli.Command{
Name: "fields",