Search in sources :

Example 26 with GetSettingsResponse

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"));
}
Also used : GetSettingsResponse(org.opensearch.action.admin.indices.settings.get.GetSettingsResponse)

Example 27 with GetSettingsResponse

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));
}
Also used : GetSettingsResponse(org.opensearch.action.admin.indices.settings.get.GetSettingsResponse)

Example 28 with GetSettingsResponse

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());
}
Also used : ClusterHealthResponse(org.opensearch.action.admin.cluster.health.ClusterHealthResponse) GetSettingsResponse(org.opensearch.action.admin.indices.settings.get.GetSettingsResponse) IndexMetadata(org.opensearch.cluster.metadata.IndexMetadata)

Example 29 with GetSettingsResponse

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"));
}
Also used : GetSettingsResponse(org.opensearch.action.admin.indices.settings.get.GetSettingsResponse) Settings(org.opensearch.common.settings.Settings)

Example 30 with GetSettingsResponse

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"));
}
Also used : GetSettingsResponse(org.opensearch.action.admin.indices.settings.get.GetSettingsResponse)

Aggregations

GetSettingsResponse (org.opensearch.action.admin.indices.settings.get.GetSettingsResponse)31 Settings (org.opensearch.common.settings.Settings)14 Matchers.containsString (org.hamcrest.Matchers.containsString)10 GetSettingsRequest (org.opensearch.action.admin.indices.settings.get.GetSettingsRequest)8 IndexSettings (org.opensearch.index.IndexSettings)7 Sort (org.apache.lucene.search.Sort)4 SortField (org.apache.lucene.search.SortField)4 SortedSetSortField (org.apache.lucene.search.SortedSetSortField)4 IndicesStatsResponse (org.opensearch.action.admin.indices.stats.IndicesStatsResponse)4 IndexMetadata (org.opensearch.cluster.metadata.IndexMetadata)4 Version (org.opensearch.Version)3 ActionListener (org.opensearch.action.ActionListener)3 ClusterStateRequest (org.opensearch.action.admin.cluster.state.ClusterStateRequest)3 ClusterStateResponse (org.opensearch.action.admin.cluster.state.ClusterStateResponse)3 CommonStats (org.opensearch.action.admin.indices.stats.CommonStats)3 Client (org.opensearch.client.Client)3 ClusterState (org.opensearch.cluster.ClusterState)3 TermsQueryBuilder (org.opensearch.index.query.TermsQueryBuilder)3 SeqNoStats (org.opensearch.index.seqno.SeqNoStats)3 IOException (java.io.IOException)2