This repository was archived by the owner on Sep 27, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathoptimize.go
More file actions
65 lines (54 loc) · 1.38 KB
/
Copy pathoptimize.go
File metadata and controls
65 lines (54 loc) · 1.38 KB
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
package main
import (
"log"
"net/url"
)
var cmdOptimize = &Command{
Run: runOptimize,
Usage: "optimize [-r -f] [index]",
Short: "optimizes indices",
Long: `
Optimize basically optimizes the index for faster search operations.
Use -r, -r=true, -r=false to enable/disable refresh (enabled by default).
Use -f, -f=true, -f=false to enable/disable flush (enabled by default).
Example:
$ es optimize
$ es optimize -f=false twitter
$ es optimize twitter
`,
ApiUrl: "http://www.elasticsearch.org/guide/reference/api/admin-indices-optimize.html",
}
func init() {
cmdOptimize.Flag.BoolVar(&flush, "f", true, "flush")
cmdOptimize.Flag.BoolVar(&refresh, "r", true, "refresh")
}
func runOptimize(cmd *Command, args []string) {
index := ""
if len(args) >= 1 {
index = args[len(args)-1]
}
values := url.Values{}
if flush {
values.Set("flush", "1")
} else {
values.Set("flush", "0")
}
if refresh {
values.Set("refresh", "1")
} else {
values.Set("refresh", "0")
}
var response struct {
Ok bool `json:"ok,omitempty"`
Error string `json:"error,omitempty"`
Status int `json:"status,omitempty"`
}
if len(index) > 0 {
ESReq("POST", "/"+index+"/_optimize?"+values.Encode()).Do(&response)
} else {
ESReq("POST", "/_optimize?"+values.Encode()).Do(&response)
}
if len(response.Error) > 0 {
log.Fatalf("Error: %v (%v)\n", response.Error, response.Status)
}
}