Update Settings API: Allow body request to be wrapped with `settings` element to conform with other APIs, closes #2227.
This commit is contained in:
parent
c834bca43c
commit
edfbfc1c87
|
@ -58,10 +58,19 @@ public class RestUpdateSettingsAction extends BaseRestHandler {
|
||||||
updateSettingsRequest.listenerThreaded(false);
|
updateSettingsRequest.listenerThreaded(false);
|
||||||
|
|
||||||
ImmutableSettings.Builder updateSettings = ImmutableSettings.settingsBuilder();
|
ImmutableSettings.Builder updateSettings = ImmutableSettings.settingsBuilder();
|
||||||
String bodySettings = request.content().toUtf8();
|
String bodySettingsStr = request.content().toUtf8();
|
||||||
if (Strings.hasText(bodySettings)) {
|
if (Strings.hasText(bodySettingsStr)) {
|
||||||
try {
|
try {
|
||||||
updateSettings.put(ImmutableSettings.settingsBuilder().loadFromSource(bodySettings).build());
|
Settings buildSettings = ImmutableSettings.settingsBuilder().loadFromSource(bodySettingsStr).build();
|
||||||
|
for (Map.Entry<String, String> entry : buildSettings.getAsMap().entrySet()) {
|
||||||
|
String key = entry.getKey();
|
||||||
|
String value = entry.getValue();
|
||||||
|
// clean up in case the body is wrapped with "settings" : { ... }
|
||||||
|
if (key.startsWith("settings.")) {
|
||||||
|
key = key.substring("settings.".length());
|
||||||
|
}
|
||||||
|
updateSettings.put(key, value);
|
||||||
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
try {
|
try {
|
||||||
channel.sendResponse(new XContentThrowableRestResponse(request, BAD_REQUEST, new SettingsException("Failed to parse index settings", e)));
|
channel.sendResponse(new XContentThrowableRestResponse(request, BAD_REQUEST, new SettingsException("Failed to parse index settings", e)));
|
||||||
|
|
Loading…
Reference in New Issue