controller.registerHandler(RestRequest.Method.PUT, "/{index}/_settings", this);
controller.registerHandler(RestRequest.Method.PUT, "/_settings", this);
}
@Override public void handleRequest(final RestRequest request, final RestChannel channel) {
UpdateSettingsRequest updateSettingsRequest = updateSettingsRequest(splitIndices(request.param("index")));
ImmutableSettings.Builder updateSettings = ImmutableSettings.settingsBuilder();
String bodySettings = request.contentAsString();
if (Strings.hasText(bodySettings)) {
try {
updateSettings.put(ImmutableSettings.settingsBuilder().loadFromSource(bodySettings).build());
} catch (Exception e) {
try {
channel.sendResponse(new XContentThrowableRestResponse(request, BAD_REQUEST, new SettingsException("Failed to parse index settings", e)));
} catch (IOException e1) {
logger.warn("Failed to send response", e1);
}
return;
}
}
for (Map.Entry<String, String> entry : request.params().entrySet()) {
if (entry.getKey().equals("pretty")) {
continue;
}
updateSettings.put(entry.getKey(), entry.getValue());
}
updateSettingsRequest.settings(updateSettings);
client.admin().indices().updateSettings(updateSettingsRequest, new ActionListener<UpdateSettingsResponse>() {
@Override public void onResponse(UpdateSettingsResponse updateSettingsResponse) {
try {
XContentBuilder builder = RestXContentBuilder.restContentBuilder(request);