/
settings.go
49 lines (39 loc) · 847 Bytes
/
settings.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
package main
import (
"encoding/json"
"fmt"
"io"
"os"
"path"
"github.com/kaneshin/esindex/elasticsearch"
)
type Settings struct {
}
func NewSettings() *Settings {
return &Settings{}
}
func (cmd *Settings) Run(args []string) error {
if len(args) < 1 {
cmd.Usage(os.Stdout)
return nil
}
indexName := args[0]
cmdFlag.Parse(args[1:])
client := elasticsearch.NewClient(
elasticsearch.NewConfig().WithURL(*urlStr),
)
req := elasticsearch.NewRequest("GET", path.Join(indexName, "_settings"), nil)
res, err := client.Do(req)
if err != nil {
return err
}
b, _ := json.MarshalIndent(res[indexName], "", " ")
fmt.Println(string(b))
return nil
}
func (cmd *Settings) Name() string {
return "settings"
}
func (cmd *Settings) Usage(w io.Writer) {
fmt.Fprintf(w, "%-8s%10s %s", cmd.Name(), "<index-name>", "[options]")
}