This repository has been 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
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
New commands: settings, flush-enable, flush-disable
* Flush enable/disable are rather helpful when performing backups via rsync (see https://gist.github.com/karussell/1074906 for example)
- Loading branch information
Showing
4 changed files
with
171 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
package main | ||
|
||
import ( | ||
"log" | ||
) | ||
|
||
var cmdFlushDisable = &Command{ | ||
Run: runFlushDisable, | ||
Usage: "flush-disable [index]", | ||
Short: "disable flush", | ||
Long: ` | ||
Disables flush. Useful if you want to prevent accidential flushes | ||
from happening, e.g. while performing a backup via rsync. | ||
Use flush-enable to revert this action. | ||
This is basically the same as: | ||
curl -XPUT 'localhost:9200/_settings' -d '{ | ||
"index" : { | ||
"translog.disable_flush" : "true" | ||
} | ||
}' | ||
Example: | ||
$ es flush-disable | ||
$ es flush-disable twitter | ||
`, | ||
ApiUrl: "http://www.elasticsearch.org/guide/reference/api/admin-indices-update-settings.html", | ||
} | ||
|
||
func runFlushDisable(cmd *Command, args []string) { | ||
index := "" | ||
if len(args) >= 1 { | ||
index = args[0] | ||
} | ||
|
||
translogReq := make(map[string]interface{}) | ||
translogReq["translog.disable_flush"] = "true" | ||
data := make(map[string]interface{}) | ||
data["index"] = translogReq | ||
|
||
var response struct { | ||
Ok bool `json:"ok,omitempty"` | ||
Error string `json:"error,omitempty"` | ||
Status int `json:"status,omitempty"` | ||
} | ||
|
||
path := "" | ||
if index != "" { | ||
path += "/"+index | ||
} | ||
path += "/_settings" | ||
|
||
req := ESReq("PUT", path) | ||
req.SetBodyJson(data) | ||
req.Do(&response) | ||
|
||
if len(response.Error) > 0 { | ||
log.Fatalf("Error: %v (%v)\n", response.Error, response.Status) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
package main | ||
|
||
import ( | ||
"log" | ||
) | ||
|
||
var cmdFlushEnable = &Command{ | ||
Run: runFlushEnable, | ||
Usage: "flush-enable [index]", | ||
Short: "enable flush", | ||
Long: ` | ||
Enables flush. Useful to return to normal usage after flush has | ||
been temporarily disabled (see flush-disable) in order to | ||
perform a backup (e.g. via rsync). | ||
This is basically the same as: | ||
curl -XPUT 'localhost:9200/_settings' -d '{ | ||
"index" : { | ||
"translog.disable_flush" : "false" | ||
} | ||
}' | ||
Example: | ||
$ es flush-enable | ||
$ es flush-enable twitter | ||
`, | ||
ApiUrl: "http://www.elasticsearch.org/guide/reference/api/admin-indices-update-settings.html", | ||
} | ||
|
||
func runFlushEnable(cmd *Command, args []string) { | ||
index := "" | ||
if len(args) >= 1 { | ||
index = args[0] | ||
} | ||
|
||
translogReq := make(map[string]interface{}) | ||
translogReq["translog.disable_flush"] = "false" | ||
data := make(map[string]interface{}) | ||
data["index"] = translogReq | ||
|
||
var response struct { | ||
Ok bool `json:"ok,omitempty"` | ||
Error string `json:"error,omitempty"` | ||
Status int `json:"status,omitempty"` | ||
} | ||
|
||
path := "" | ||
if index != "" { | ||
path += "/"+index | ||
} | ||
path += "/_settings" | ||
|
||
req := ESReq("PUT", path) | ||
req.SetBodyJson(data) | ||
req.Do(&response) | ||
|
||
if len(response.Error) > 0 { | ||
log.Fatalf("Error: %v (%v)\n", response.Error, response.Status) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
"log" | ||
) | ||
|
||
var cmdSettings = &Command{ | ||
Run: runSettings, | ||
Usage: "settings [index]", | ||
Short: "prints index settings", | ||
Long: ` | ||
Prints index settings. | ||
Example: | ||
$ es settings | ||
$ es settings twitter | ||
`, | ||
ApiUrl: "http://www.elasticsearch.org/guide/reference/api/admin-indices-get-settings.html", | ||
} | ||
|
||
func runSettings(cmd *Command, args []string) { | ||
index := "" | ||
if len(args) >= 1 { | ||
index = args[0] | ||
} | ||
|
||
var response map[string]interface{} | ||
|
||
var body string | ||
if len(index) > 0 { | ||
body = ESReq("GET", "/"+index+"/_settings?pretty=1").Do(&response) | ||
} else { | ||
body = ESReq("GET", "/_settings?pretty=1").Do(&response) | ||
} | ||
|
||
if error, ok := response["error"]; ok { | ||
status, _ := response["status"] | ||
log.Fatalf("Error: %v (%v)\n", error, status) | ||
} | ||
fmt.Print(body) | ||
} |