use of org.opensearch.action.admin.indices.settings.get.GetSettingsResponse in project OpenSearch by opensearch-project.
the class PrivateSettingsIT method testUpdatePrivatelIndexSettingViaDedicatedAPI.
public void testUpdatePrivatelIndexSettingViaDedicatedAPI() {
createIndex("test");
client().execute(InternalOrPrivateSettingsPlugin.UpdateInternalOrPrivateAction.INSTANCE, new InternalOrPrivateSettingsPlugin.UpdateInternalOrPrivateAction.Request("test", "index.private", "private-update")).actionGet();
final GetSettingsResponse responseAfterUpdate = client().admin().indices().prepareGetSettings("test").get();
assertThat(responseAfterUpdate.getSetting("test", "index.private"), equalTo("private-update"));
}
use of org.opensearch.action.admin.indices.settings.get.GetSettingsResponse in project OpenSearch by opensearch-project.
the class UpdateSettingsIT method runTestDefaultNumberOfReplicasTest.
private void runTestDefaultNumberOfReplicasTest(final boolean closeIndex) {
if (randomBoolean()) {
assertAcked(client().admin().indices().prepareCreate("test").setSettings(Settings.builder().put(IndexMetadata.SETTING_NUMBER_OF_REPLICAS, randomIntBetween(1, 8))));
} else {
assertAcked(client().admin().indices().prepareCreate("test"));
}
if (closeIndex) {
assertAcked(client().admin().indices().prepareClose("test"));
}
/*
* Previous versions of Elasticsearch would throw an exception that the number of replicas had to have a value, and could not be
* null. In the update settings logic, we ensure this by providing an explicit default value if the setting is set to null.
*/
assertAcked(client().admin().indices().prepareUpdateSettings("test").setSettings(Settings.builder().putNull(IndexMetadata.SETTING_NUMBER_OF_REPLICAS)));
final GetSettingsResponse response = client().admin().indices().prepareGetSettings("test").get();
// we removed the setting but it should still have an explicit value since index metadata requires this
assertTrue(IndexMetadata.INDEX_NUMBER_OF_REPLICAS_SETTING.exists(response.getIndexToSettings().get("test")));
assertThat(IndexMetadata.INDEX_NUMBER_OF_REPLICAS_SETTING.get(response.getIndexToSettings().get("test")), equalTo(1));
}
use of org.opensearch.action.admin.indices.settings.get.GetSettingsResponse in project OpenSearch by opensearch-project.
the class UpdateSettingsIT method testOpenCloseUpdateSettings.
public void testOpenCloseUpdateSettings() throws Exception {
createIndex("test");
expectThrows(IllegalArgumentException.class, () -> client().admin().indices().prepareUpdateSettings("test").setSettings(Settings.builder().put("index.refresh_interval", // this one can change
-1).put("index.fielddata.cache", "none")).execute().actionGet());
expectThrows(IllegalArgumentException.class, () -> client().admin().indices().prepareUpdateSettings("test").setSettings(Settings.builder().put("index.refresh_interval", // this one can change
-1).put("index.final", "no")).execute().actionGet());
IndexMetadata indexMetadata = client().admin().cluster().prepareState().execute().actionGet().getState().metadata().index("test");
assertThat(indexMetadata.getSettings().get("index.refresh_interval"), nullValue());
assertThat(indexMetadata.getSettings().get("index.fielddata.cache"), nullValue());
assertThat(indexMetadata.getSettings().get("index.final"), nullValue());
// Now verify via dedicated get settings api:
GetSettingsResponse getSettingsResponse = client().admin().indices().prepareGetSettings("test").get();
assertThat(getSettingsResponse.getSetting("test", "index.refresh_interval"), nullValue());
assertThat(getSettingsResponse.getSetting("test", "index.fielddata.cache"), nullValue());
assertThat(getSettingsResponse.getSetting("test", "index.final"), nullValue());
client().admin().indices().prepareUpdateSettings("test").setSettings(// this one can change
Settings.builder().put("index.refresh_interval", -1)).execute().actionGet();
indexMetadata = client().admin().cluster().prepareState().execute().actionGet().getState().metadata().index("test");
assertThat(indexMetadata.getSettings().get("index.refresh_interval"), equalTo("-1"));
// Now verify via dedicated get settings api:
getSettingsResponse = client().admin().indices().prepareGetSettings("test").get();
assertThat(getSettingsResponse.getSetting("test", "index.refresh_interval"), equalTo("-1"));
// now close the index, change the non dynamic setting, and see that it applies
// Wait for the index to turn green before attempting to close it
ClusterHealthResponse health = client().admin().cluster().prepareHealth().setTimeout("30s").setWaitForEvents(Priority.LANGUID).setWaitForGreenStatus().execute().actionGet();
assertThat(health.isTimedOut(), equalTo(false));
client().admin().indices().prepareClose("test").execute().actionGet();
client().admin().indices().prepareUpdateSettings("test").setSettings(Settings.builder().put(IndexMetadata.SETTING_NUMBER_OF_REPLICAS, 1)).execute().actionGet();
indexMetadata = client().admin().cluster().prepareState().execute().actionGet().getState().metadata().index("test");
assertThat(indexMetadata.getNumberOfReplicas(), equalTo(1));
client().admin().indices().prepareUpdateSettings("test").setSettings(Settings.builder().put("index.refresh_interval", // this one can change
"1s").put("index.fielddata.cache", "none")).execute().actionGet();
indexMetadata = client().admin().cluster().prepareState().execute().actionGet().getState().metadata().index("test");
assertThat(indexMetadata.getSettings().get("index.refresh_interval"), equalTo("1s"));
assertThat(indexMetadata.getSettings().get("index.fielddata.cache"), equalTo("none"));
IllegalArgumentException ex = expectThrows(IllegalArgumentException.class, () -> client().admin().indices().prepareUpdateSettings("test").setSettings(Settings.builder().put("index.refresh_interval", // this one can change
-1).put("index.final", "no")).execute().actionGet());
assertThat(ex.getMessage(), containsString("final test setting [index.final], not updateable"));
indexMetadata = client().admin().cluster().prepareState().execute().actionGet().getState().metadata().index("test");
assertThat(indexMetadata.getSettings().get("index.refresh_interval"), equalTo("1s"));
assertThat(indexMetadata.getSettings().get("index.final"), nullValue());
// Now verify via dedicated get settings api:
getSettingsResponse = client().admin().indices().prepareGetSettings("test").get();
assertThat(getSettingsResponse.getSetting("test", "index.refresh_interval"), equalTo("1s"));
assertThat(getSettingsResponse.getSetting("test", "index.final"), nullValue());
}
use of org.opensearch.action.admin.indices.settings.get.GetSettingsResponse in project OpenSearch by opensearch-project.
the class InternalSettingsIT method testSetInternalIndexSettingOnCreate.
public void testSetInternalIndexSettingOnCreate() {
final Settings settings = Settings.builder().put("index.internal", "internal").build();
createIndex("index", settings);
final GetSettingsResponse response = client().admin().indices().prepareGetSettings("index").get();
assertThat(response.getSetting("index", "index.internal"), equalTo("internal"));
}
use of org.opensearch.action.admin.indices.settings.get.GetSettingsResponse in project OpenSearch by opensearch-project.
the class HiddenIndexIT method testNonGlobalTemplateCanMakeIndexHidden.
public void testNonGlobalTemplateCanMakeIndexHidden() {
assertAcked(client().admin().indices().preparePutTemplate("a_global_template").setPatterns(Collections.singletonList("my_hidden_pattern*")).addMapping("_doc", "foo", "type=text").setSettings(Settings.builder().put("index.hidden", true).build()).get());
assertAcked(client().admin().indices().prepareCreate("my_hidden_pattern1").get());
GetSettingsResponse getSettingsResponse = client().admin().indices().prepareGetSettings("my_hidden_pattern1").get();
assertThat(getSettingsResponse.getSetting("my_hidden_pattern1", "index.hidden"), is("true"));
}
Aggregations