use of org.opensearch.action.admin.indices.settings.put.UpdateSettingsRequest in project OpenSearch by opensearch-project.
the class IndicesClientIT method testIndexPutSettingNonExistent.
public void testIndexPutSettingNonExistent() throws IOException {
String index = "index";
UpdateSettingsRequest indexUpdateSettingsRequest = new UpdateSettingsRequest(index);
String setting = "no_idea_what_you_are_talking_about";
int value = 10;
indexUpdateSettingsRequest.settings(Settings.builder().put(setting, value).build());
OpenSearchException exception = expectThrows(OpenSearchException.class, () -> execute(indexUpdateSettingsRequest, highLevelClient().indices()::putSettings, highLevelClient().indices()::putSettingsAsync));
assertEquals(RestStatus.NOT_FOUND, exception.status());
assertThat(exception.getMessage(), equalTo("OpenSearch exception [type=index_not_found_exception, reason=no such index [index]]"));
createIndex(index, Settings.EMPTY);
exception = expectThrows(OpenSearchException.class, () -> execute(indexUpdateSettingsRequest, highLevelClient().indices()::putSettings, highLevelClient().indices()::putSettingsAsync));
assertThat(exception.status(), equalTo(RestStatus.BAD_REQUEST));
assertThat(exception.getMessage(), equalTo("OpenSearch exception [type=illegal_argument_exception, " + "reason=unknown setting [index.no_idea_what_you_are_talking_about] please check that any required plugins are installed, " + "or check the breaking changes documentation for removed settings]"));
}
use of org.opensearch.action.admin.indices.settings.put.UpdateSettingsRequest in project OpenSearch by opensearch-project.
the class IndicesClientIT method testIndexPutSettings.
public void testIndexPutSettings() throws IOException {
final Setting<Integer> dynamicSetting = IndexMetadata.INDEX_NUMBER_OF_REPLICAS_SETTING;
final String dynamicSettingKey = IndexMetadata.SETTING_NUMBER_OF_REPLICAS;
final int dynamicSettingValue = 0;
final Setting<String> staticSetting = IndexSettings.INDEX_CHECK_ON_STARTUP;
final String staticSettingKey = IndexSettings.INDEX_CHECK_ON_STARTUP.getKey();
final String staticSettingValue = "true";
final Setting<Integer> unmodifiableSetting = IndexMetadata.INDEX_NUMBER_OF_SHARDS_SETTING;
final String unmodifiableSettingKey = IndexMetadata.SETTING_NUMBER_OF_SHARDS;
final int unmodifiableSettingValue = 3;
String index = "index";
createIndex(index, Settings.EMPTY);
assertThat(dynamicSetting.getDefault(Settings.EMPTY), not(dynamicSettingValue));
UpdateSettingsRequest dynamicSettingRequest = new UpdateSettingsRequest(index);
dynamicSettingRequest.settings(Settings.builder().put(dynamicSettingKey, dynamicSettingValue).build());
AcknowledgedResponse response = execute(dynamicSettingRequest, highLevelClient().indices()::putSettings, highLevelClient().indices()::putSettingsAsync);
assertTrue(response.isAcknowledged());
Map<String, Object> indexSettingsAsMap = getIndexSettingsAsMap(index);
assertThat(indexSettingsAsMap.get(dynamicSettingKey), equalTo(String.valueOf(dynamicSettingValue)));
assertThat(staticSetting.getDefault(Settings.EMPTY), not(staticSettingValue));
UpdateSettingsRequest staticSettingRequest = new UpdateSettingsRequest(index);
staticSettingRequest.settings(Settings.builder().put(staticSettingKey, staticSettingValue).build());
OpenSearchException exception = expectThrows(OpenSearchException.class, () -> execute(staticSettingRequest, highLevelClient().indices()::putSettings, highLevelClient().indices()::putSettingsAsync));
assertThat(exception.getMessage(), startsWith("OpenSearch exception [type=illegal_argument_exception, " + "reason=Can't update non dynamic settings [[index.shard.check_on_startup]] for open indices [[index/"));
indexSettingsAsMap = getIndexSettingsAsMap(index);
assertNull(indexSettingsAsMap.get(staticSettingKey));
closeIndex(index);
response = execute(staticSettingRequest, highLevelClient().indices()::putSettings, highLevelClient().indices()::putSettingsAsync);
assertTrue(response.isAcknowledged());
openIndex(index);
indexSettingsAsMap = getIndexSettingsAsMap(index);
assertThat(indexSettingsAsMap.get(staticSettingKey), equalTo(staticSettingValue));
assertThat(unmodifiableSetting.getDefault(Settings.EMPTY), not(unmodifiableSettingValue));
UpdateSettingsRequest unmodifiableSettingRequest = new UpdateSettingsRequest(index);
unmodifiableSettingRequest.settings(Settings.builder().put(unmodifiableSettingKey, unmodifiableSettingValue).build());
exception = expectThrows(OpenSearchException.class, () -> execute(unmodifiableSettingRequest, highLevelClient().indices()::putSettings, highLevelClient().indices()::putSettingsAsync));
assertThat(exception.getMessage(), startsWith("OpenSearch exception [type=illegal_argument_exception, " + "reason=Can't update non dynamic settings [[index.number_of_shards]] for open indices [[index/"));
closeIndex(index);
exception = expectThrows(OpenSearchException.class, () -> execute(unmodifiableSettingRequest, highLevelClient().indices()::putSettings, highLevelClient().indices()::putSettingsAsync));
assertThat(exception.getMessage(), startsWith("OpenSearch exception [type=illegal_argument_exception, " + "reason=final index setting [index.number_of_shards], not updateable"));
}
use of org.opensearch.action.admin.indices.settings.put.UpdateSettingsRequest in project OpenSearch by opensearch-project.
the class IndicesRequestConvertersTests method testIndexPutSettings.
public void testIndexPutSettings() throws IOException {
String[] indices = OpenSearchTestCase.randomBoolean() ? null : RequestConvertersTests.randomIndicesNames(0, 2);
UpdateSettingsRequest updateSettingsRequest = new UpdateSettingsRequest(indices);
Map<String, String> expectedParams = new HashMap<>();
RequestConvertersTests.setRandomMasterTimeout(updateSettingsRequest, expectedParams);
RequestConvertersTests.setRandomTimeout(updateSettingsRequest::timeout, AcknowledgedRequest.DEFAULT_ACK_TIMEOUT, expectedParams);
RequestConvertersTests.setRandomIndicesOptions(updateSettingsRequest::indicesOptions, updateSettingsRequest::indicesOptions, expectedParams);
if (OpenSearchTestCase.randomBoolean()) {
updateSettingsRequest.setPreserveExisting(OpenSearchTestCase.randomBoolean());
if (updateSettingsRequest.isPreserveExisting()) {
expectedParams.put("preserve_existing", "true");
}
}
Request request = IndicesRequestConverters.indexPutSettings(updateSettingsRequest);
StringJoiner endpoint = new StringJoiner("/", "/", "");
if (indices != null && indices.length > 0) {
endpoint.add(String.join(",", indices));
}
endpoint.add("_settings");
Assert.assertThat(endpoint.toString(), equalTo(request.getEndpoint()));
Assert.assertEquals(HttpPut.METHOD_NAME, request.getMethod());
RequestConvertersTests.assertToXContentBody(updateSettingsRequest, request.getEntity());
Assert.assertEquals(expectedParams, request.getParameters());
}
use of org.opensearch.action.admin.indices.settings.put.UpdateSettingsRequest in project OpenSearch by opensearch-project.
the class IndicesClientDocumentationIT method testIndexPutSettings.
@SuppressWarnings("unused")
public void testIndexPutSettings() throws Exception {
RestHighLevelClient client = highLevelClient();
{
CreateIndexResponse createIndexResponse = client.indices().create(new CreateIndexRequest("index"), RequestOptions.DEFAULT);
assertTrue(createIndexResponse.isAcknowledged());
}
// tag::indices-put-settings-request
// <1>
UpdateSettingsRequest request = new UpdateSettingsRequest("index1");
UpdateSettingsRequest requestMultiple = // <2>
new UpdateSettingsRequest("index1", "index2");
// <3>
UpdateSettingsRequest requestAll = new UpdateSettingsRequest();
// end::indices-put-settings-request
// tag::indices-put-settings-create-settings
String settingKey = "index.number_of_replicas";
int settingValue = 0;
Settings settings = Settings.builder().put(settingKey, settingValue).build();
// end::indices-put-settings-create-settings
// tag::indices-put-settings-request-index-settings
request.settings(settings);
// end::indices-put-settings-request-index-settings
{
// tag::indices-put-settings-settings-builder
Settings.Builder settingsBuilder = Settings.builder().put(settingKey, settingValue);
// <1>
request.settings(settingsBuilder);
// end::indices-put-settings-settings-builder
}
{
// tag::indices-put-settings-settings-map
Map<String, Object> map = new HashMap<>();
map.put(settingKey, settingValue);
// <1>
request.settings(map);
// end::indices-put-settings-settings-map
}
{
// tag::indices-put-settings-settings-source
request.settings("{\"index.number_of_replicas\": \"2\"}", // <1>
XContentType.JSON);
// end::indices-put-settings-settings-source
}
// tag::indices-put-settings-request-preserveExisting
// <1>
request.setPreserveExisting(false);
// end::indices-put-settings-request-preserveExisting
// tag::indices-put-settings-request-timeout
// <1>
request.timeout(TimeValue.timeValueMinutes(2));
// <2>
request.timeout("2m");
// end::indices-put-settings-request-timeout
// tag::indices-put-settings-request-masterTimeout
// <1>
request.masterNodeTimeout(TimeValue.timeValueMinutes(1));
// <2>
request.masterNodeTimeout("1m");
// end::indices-put-settings-request-masterTimeout
// tag::indices-put-settings-request-indicesOptions
// <1>
request.indicesOptions(IndicesOptions.lenientExpandOpen());
// end::indices-put-settings-request-indicesOptions
// tag::indices-put-settings-execute
AcknowledgedResponse updateSettingsResponse = client.indices().putSettings(request, RequestOptions.DEFAULT);
// end::indices-put-settings-execute
// tag::indices-put-settings-response
// <1>
boolean acknowledged = updateSettingsResponse.isAcknowledged();
// end::indices-put-settings-response
assertTrue(acknowledged);
// tag::indices-put-settings-execute-listener
ActionListener<AcknowledgedResponse> listener = new ActionListener<AcknowledgedResponse>() {
@Override
public void onResponse(AcknowledgedResponse updateSettingsResponse) {
// <1>
}
@Override
public void onFailure(Exception e) {
// <2>
}
};
// end::indices-put-settings-execute-listener
// Replace the empty listener by a blocking listener in test
final CountDownLatch latch = new CountDownLatch(1);
listener = new LatchedActionListener<>(listener, latch);
// tag::indices-put-settings-execute-async
// <1>
client.indices().putSettingsAsync(request, RequestOptions.DEFAULT, listener);
// end::indices-put-settings-execute-async
assertTrue(latch.await(30L, TimeUnit.SECONDS));
}
use of org.opensearch.action.admin.indices.settings.put.UpdateSettingsRequest in project OpenSearch by opensearch-project.
the class IndicesRequestIT method testUpdateSettings.
public void testUpdateSettings() {
interceptTransportActions(UpdateSettingsAction.NAME);
UpdateSettingsRequest updateSettingsRequest = new UpdateSettingsRequest(randomIndicesOrAliases()).settings(Settings.builder().put("refresh_interval", -1));
internalCluster().coordOnlyNodeClient().admin().indices().updateSettings(updateSettingsRequest).actionGet();
clearInterceptedActions();
assertSameIndices(updateSettingsRequest, UpdateSettingsAction.NAME);
}
Aggregations