Skip to content

Commit 495b246

Browse files
authored
Update indices settings api to support CBOR and SMILE format (#23309)
Also expand testing on the different ways to provide index settings and remove dead code around ability to provide settings as query string parameters Closes #23242
1 parent 594f00c commit 495b246

File tree

2 files changed

+18
-36
lines changed

2 files changed

+18
-36
lines changed

core/src/main/java/org/elasticsearch/rest/action/admin/indices/RestUpdateSettingsAction.java

Lines changed: 14 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -24,30 +24,20 @@
2424
import org.elasticsearch.client.node.NodeClient;
2525
import org.elasticsearch.common.Strings;
2626
import org.elasticsearch.common.settings.Settings;
27+
import org.elasticsearch.common.xcontent.XContentParser;
2728
import org.elasticsearch.rest.BaseRestHandler;
2829
import org.elasticsearch.rest.RestController;
2930
import org.elasticsearch.rest.RestRequest;
3031
import org.elasticsearch.rest.action.AcknowledgedRestListener;
3132

3233
import java.io.IOException;
34+
import java.util.HashMap;
3335
import java.util.Map;
3436
import java.util.Set;
3537

36-
import static java.util.Collections.unmodifiableSet;
3738
import static org.elasticsearch.client.Requests.updateSettingsRequest;
38-
import static org.elasticsearch.common.util.set.Sets.newHashSet;
3939

4040
public class RestUpdateSettingsAction extends BaseRestHandler {
41-
private static final Set<String> VALUES_TO_EXCLUDE = unmodifiableSet(newHashSet(
42-
"error_trace",
43-
"pretty",
44-
"timeout",
45-
"master_timeout",
46-
"index",
47-
"preserve_existing",
48-
"expand_wildcards",
49-
"ignore_unavailable",
50-
"allow_no_indices"));
5141

5242
public RestUpdateSettingsAction(Settings settings, RestController controller) {
5343
super(settings);
@@ -63,29 +53,22 @@ public RestChannelConsumer prepareRequest(final RestRequest request, final NodeC
6353
updateSettingsRequest.masterNodeTimeout(request.paramAsTime("master_timeout", updateSettingsRequest.masterNodeTimeout()));
6454
updateSettingsRequest.indicesOptions(IndicesOptions.fromRequest(request, updateSettingsRequest.indicesOptions()));
6555

66-
Settings.Builder updateSettings = Settings.builder();
67-
String bodySettingsStr = request.content().utf8ToString();
68-
if (Strings.hasText(bodySettingsStr)) {
69-
Settings buildSettings = Settings.builder()
70-
.loadFromSource(bodySettingsStr, request.getXContentType())
71-
.build();
72-
for (Map.Entry<String, String> entry : buildSettings.getAsMap().entrySet()) {
73-
String key = entry.getKey();
74-
String value = entry.getValue();
56+
Map<String, Object> settings = new HashMap<>();
57+
if (request.hasContent()) {
58+
try (XContentParser parser = request.contentParser()) {
59+
Map<String, Object> bodySettings = parser.map();
60+
Object innerBodySettings = bodySettings.get("settings");
7561
// clean up in case the body is wrapped with "settings" : { ... }
76-
if (key.startsWith("settings.")) {
77-
key = key.substring("settings.".length());
62+
if (innerBodySettings instanceof Map) {
63+
@SuppressWarnings("unchecked")
64+
Map<String, Object> innerBodySettingsMap = (Map<String, Object>) innerBodySettings;
65+
settings.putAll(innerBodySettingsMap);
66+
} else {
67+
settings.putAll(bodySettings);
7868
}
79-
updateSettings.put(key, value);
8069
}
8170
}
82-
for (Map.Entry<String, String> entry : request.params().entrySet()) {
83-
if (VALUES_TO_EXCLUDE.contains(entry.getKey())) {
84-
continue;
85-
}
86-
updateSettings.put(entry.getKey(), entry.getValue());
87-
}
88-
updateSettingsRequest.settings(updateSettings);
71+
updateSettingsRequest.settings(settings);
8972

9073
return channel -> client.admin().indices().updateSettings(updateSettingsRequest, new AcknowledgedRestListener<>(channel));
9174
}
@@ -94,5 +77,4 @@ public RestChannelConsumer prepareRequest(final RestRequest request, final NodeC
9477
protected Set<String> responseParams() {
9578
return Settings.FORMAT_PARAMS;
9679
}
97-
9880
}

rest-api-spec/src/main/resources/rest-api-spec/test/indices.put_settings/10_basic.yaml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ setup:
3636
ignore_unavailable: true
3737
index: test-index, non-existing
3838
body:
39-
number_of_replicas: 1
39+
index.number_of_replicas: 1
4040

4141
- do:
4242
indices.get_settings: {}
@@ -81,7 +81,6 @@ setup:
8181
indices.get_settings:
8282
flat_settings: false
8383

84-
8584
- match:
8685
test-index.settings.index.number_of_replicas: "0"
8786
- match:
@@ -96,8 +95,9 @@ setup:
9695
preserve_existing: true
9796
index: test-index
9897
body:
99-
index.translog.durability: "request"
100-
index.query_string.lenient: "true"
98+
settings:
99+
index.translog.durability: "request"
100+
index.query_string.lenient: "true"
101101

102102
- do:
103103
indices.get_settings:

0 commit comments

Comments
 (0)