Search in sources :

Example 11 with GetSettingsResponse

use of org.opensearch.action.admin.indices.settings.get.GetSettingsResponse in project OpenSearch by opensearch-project.

the class RolloverIT method testRolloverWithDateMath.

public void testRolloverWithDateMath() {
    ZonedDateTime now = ZonedDateTime.now(ZoneOffset.UTC);
    assumeTrue("only works on the same day", now.plusMinutes(5).getDayOfYear() == now.getDayOfYear());
    String index = "test-" + DateFormatter.forPattern("yyyy.MM.dd").format(now) + "-1";
    String dateMathExp = "<test-{now/d}-1>";
    assertAcked(prepareCreate(dateMathExp).addAlias(new Alias("test_alias")).get());
    ensureGreen(index);
    // now we modify the provided name such that we can test that the pattern is carried on
    client().admin().indices().prepareClose(index).get();
    client().admin().indices().prepareUpdateSettings(index).setSettings(Settings.builder().put(IndexMetadata.SETTING_INDEX_PROVIDED_NAME, "<test-{now/M{yyyy.MM}}-1>")).get();
    client().admin().indices().prepareOpen(index).get();
    ensureGreen(index);
    RolloverResponse response = client().admin().indices().prepareRolloverIndex("test_alias").get();
    assertThat(response.getOldIndex(), equalTo(index));
    assertThat(response.getNewIndex(), equalTo("test-" + DateFormatter.forPattern("yyyy.MM").format(now) + "-000002"));
    assertThat(response.isDryRun(), equalTo(false));
    assertThat(response.isRolledOver(), equalTo(true));
    assertThat(response.getConditionStatus().size(), equalTo(0));
    response = client().admin().indices().prepareRolloverIndex("test_alias").get();
    assertThat(response.getOldIndex(), equalTo("test-" + DateFormatter.forPattern("yyyy.MM").format(now) + "-000002"));
    assertThat(response.getNewIndex(), equalTo("test-" + DateFormatter.forPattern("yyyy.MM").format(now) + "-000003"));
    assertThat(response.isDryRun(), equalTo(false));
    assertThat(response.isRolledOver(), equalTo(true));
    assertThat(response.getConditionStatus().size(), equalTo(0));
    GetSettingsResponse getSettingsResponse = client().admin().indices().prepareGetSettings(response.getOldIndex(), response.getNewIndex()).get();
    assertEquals("<test-{now/M{yyyy.MM}}-000002>", getSettingsResponse.getSetting(response.getOldIndex(), IndexMetadata.SETTING_INDEX_PROVIDED_NAME));
    assertEquals("<test-{now/M{yyyy.MM}}-000003>", getSettingsResponse.getSetting(response.getNewIndex(), IndexMetadata.SETTING_INDEX_PROVIDED_NAME));
    response = client().admin().indices().prepareRolloverIndex("test_alias").setNewIndexName("<test-{now/d}-000004>").get();
    assertThat(response.getOldIndex(), equalTo("test-" + DateFormatter.forPattern("yyyy.MM").format(now) + "-000003"));
    assertThat(response.getNewIndex(), equalTo("test-" + DateFormatter.forPattern("yyyy.MM.dd").format(now) + "-000004"));
    assertThat(response.isDryRun(), equalTo(false));
    assertThat(response.isRolledOver(), equalTo(true));
    assertThat(response.getConditionStatus().size(), equalTo(0));
}
Also used : ZonedDateTime(java.time.ZonedDateTime) GetSettingsResponse(org.opensearch.action.admin.indices.settings.get.GetSettingsResponse) Alias(org.opensearch.action.admin.indices.alias.Alias)

Example 12 with GetSettingsResponse

use of org.opensearch.action.admin.indices.settings.get.GetSettingsResponse in project OpenSearch by opensearch-project.

the class DateMathIndexExpressionsIntegrationIT method testIndexNameDateMathExpressions.

public void testIndexNameDateMathExpressions() {
    DateTime now = new DateTime(DateTimeZone.UTC);
    String index1 = ".marvel-" + DateTimeFormat.forPattern("YYYY.MM.dd").print(now);
    String index2 = ".marvel-" + DateTimeFormat.forPattern("YYYY.MM.dd").print(now.minusDays(1));
    String index3 = ".marvel-" + DateTimeFormat.forPattern("YYYY.MM.dd").print(now.minusDays(2));
    createIndex(index1, index2, index3);
    GetSettingsResponse getSettingsResponse = client().admin().indices().prepareGetSettings(index1, index2, index3).get();
    assertEquals(index1, getSettingsResponse.getSetting(index1, IndexMetadata.SETTING_INDEX_PROVIDED_NAME));
    assertEquals(index2, getSettingsResponse.getSetting(index2, IndexMetadata.SETTING_INDEX_PROVIDED_NAME));
    assertEquals(index3, getSettingsResponse.getSetting(index3, IndexMetadata.SETTING_INDEX_PROVIDED_NAME));
    String dateMathExp1 = "<.marvel-{now/d}>";
    String dateMathExp2 = "<.marvel-{now/d-1d}>";
    String dateMathExp3 = "<.marvel-{now/d-2d}>";
    client().prepareIndex(dateMathExp1).setId("1").setSource("{}", XContentType.JSON).get();
    client().prepareIndex(dateMathExp2).setId("2").setSource("{}", XContentType.JSON).get();
    client().prepareIndex(dateMathExp3).setId("3").setSource("{}", XContentType.JSON).get();
    refresh();
    SearchResponse searchResponse = client().prepareSearch(dateMathExp1, dateMathExp2, dateMathExp3).get();
    assertHitCount(searchResponse, 3);
    assertSearchHits(searchResponse, "1", "2", "3");
    GetResponse getResponse = client().prepareGet(dateMathExp1, "1").get();
    assertThat(getResponse.isExists(), is(true));
    assertThat(getResponse.getId(), equalTo("1"));
    getResponse = client().prepareGet(dateMathExp2, "2").get();
    assertThat(getResponse.isExists(), is(true));
    assertThat(getResponse.getId(), equalTo("2"));
    getResponse = client().prepareGet(dateMathExp3, "3").get();
    assertThat(getResponse.isExists(), is(true));
    assertThat(getResponse.getId(), equalTo("3"));
    MultiGetResponse mgetResponse = client().prepareMultiGet().add(dateMathExp1, "1").add(dateMathExp2, "2").add(dateMathExp3, "3").get();
    assertThat(mgetResponse.getResponses()[0].getResponse().isExists(), is(true));
    assertThat(mgetResponse.getResponses()[0].getResponse().getId(), equalTo("1"));
    assertThat(mgetResponse.getResponses()[1].getResponse().isExists(), is(true));
    assertThat(mgetResponse.getResponses()[1].getResponse().getId(), equalTo("2"));
    assertThat(mgetResponse.getResponses()[2].getResponse().isExists(), is(true));
    assertThat(mgetResponse.getResponses()[2].getResponse().getId(), equalTo("3"));
    IndicesStatsResponse indicesStatsResponse = client().admin().indices().prepareStats(dateMathExp1, dateMathExp2, dateMathExp3).get();
    assertThat(indicesStatsResponse.getIndex(index1), notNullValue());
    assertThat(indicesStatsResponse.getIndex(index2), notNullValue());
    assertThat(indicesStatsResponse.getIndex(index3), notNullValue());
    DeleteResponse deleteResponse = client().prepareDelete(dateMathExp1, "1").get();
    assertEquals(DocWriteResponse.Result.DELETED, deleteResponse.getResult());
    assertThat(deleteResponse.getId(), equalTo("1"));
    deleteResponse = client().prepareDelete(dateMathExp2, "2").get();
    assertEquals(DocWriteResponse.Result.DELETED, deleteResponse.getResult());
    assertThat(deleteResponse.getId(), equalTo("2"));
    deleteResponse = client().prepareDelete(dateMathExp3, "3").get();
    assertEquals(DocWriteResponse.Result.DELETED, deleteResponse.getResult());
    assertThat(deleteResponse.getId(), equalTo("3"));
}
Also used : MultiGetResponse(org.opensearch.action.get.MultiGetResponse) IndicesStatsResponse(org.opensearch.action.admin.indices.stats.IndicesStatsResponse) DeleteResponse(org.opensearch.action.delete.DeleteResponse) GetSettingsResponse(org.opensearch.action.admin.indices.settings.get.GetSettingsResponse) MultiGetResponse(org.opensearch.action.get.MultiGetResponse) GetResponse(org.opensearch.action.get.GetResponse) DateTime(org.joda.time.DateTime) SearchResponse(org.opensearch.action.search.SearchResponse)

Example 13 with GetSettingsResponse

use of org.opensearch.action.admin.indices.settings.get.GetSettingsResponse in project OpenSearch by opensearch-project.

the class DateMathIndexExpressionsIntegrationIT method testCreateIndexWithDateMathExpression.

public void testCreateIndexWithDateMathExpression() throws Exception {
    DateTime now = new DateTime(DateTimeZone.UTC);
    String index1 = ".marvel-" + DateTimeFormat.forPattern("YYYY.MM.dd").print(now);
    String index2 = ".marvel-" + DateTimeFormat.forPattern("YYYY.MM.dd").print(now.minusDays(1));
    String index3 = ".marvel-" + DateTimeFormat.forPattern("YYYY.MM.dd").print(now.minusDays(2));
    String dateMathExp1 = "<.marvel-{now/d}>";
    String dateMathExp2 = "<.marvel-{now/d-1d}>";
    String dateMathExp3 = "<.marvel-{now/d-2d}>";
    createIndex(dateMathExp1, dateMathExp2, dateMathExp3);
    GetSettingsResponse getSettingsResponse = client().admin().indices().prepareGetSettings(index1, index2, index3).get();
    assertEquals(dateMathExp1, getSettingsResponse.getSetting(index1, IndexMetadata.SETTING_INDEX_PROVIDED_NAME));
    assertEquals(dateMathExp2, getSettingsResponse.getSetting(index2, IndexMetadata.SETTING_INDEX_PROVIDED_NAME));
    assertEquals(dateMathExp3, getSettingsResponse.getSetting(index3, IndexMetadata.SETTING_INDEX_PROVIDED_NAME));
    ClusterState clusterState = client().admin().cluster().prepareState().get().getState();
    assertThat(clusterState.metadata().index(index1), notNullValue());
    assertThat(clusterState.metadata().index(index2), notNullValue());
    assertThat(clusterState.metadata().index(index3), notNullValue());
}
Also used : ClusterState(org.opensearch.cluster.ClusterState) GetSettingsResponse(org.opensearch.action.admin.indices.settings.get.GetSettingsResponse) DateTime(org.joda.time.DateTime)

Example 14 with GetSettingsResponse

use of org.opensearch.action.admin.indices.settings.get.GetSettingsResponse in project OpenSearch by opensearch-project.

the class PrivateSettingsIT method testUpdatePrivateIndexSettingViaSettingsAPI.

public void testUpdatePrivateIndexSettingViaSettingsAPI() {
    createIndex("test");
    // we can not update the setting via the update settings API
    final IllegalArgumentException e = expectThrows(IllegalArgumentException.class, () -> client().admin().indices().prepareUpdateSettings("test").setSettings(Settings.builder().put("index.private", "private-update")).get());
    final String message = "can not update private setting [index.private]; this setting is managed by OpenSearch";
    assertThat(e, hasToString(containsString(message)));
    final GetSettingsResponse responseAfterAttemptedUpdate = client().admin().indices().prepareGetSettings("test").get();
    assertNull(responseAfterAttemptedUpdate.getSetting("test", "index.private"));
}
Also used : GetSettingsResponse(org.opensearch.action.admin.indices.settings.get.GetSettingsResponse) Matchers.hasToString(org.hamcrest.Matchers.hasToString) Matchers.containsString(org.hamcrest.Matchers.containsString)

Example 15 with GetSettingsResponse

use of org.opensearch.action.admin.indices.settings.get.GetSettingsResponse in project OpenSearch by opensearch-project.

the class IndicesOptionsIntegrationIT method testUpdateSettings.

public void testUpdateSettings() throws Exception {
    verify(client().admin().indices().prepareUpdateSettings("foo").setSettings(Settings.builder().put("a", "b")), true);
    verify(client().admin().indices().prepareUpdateSettings("_all").setSettings(Settings.builder().put("a", "b")), true);
    createIndex("foo", "foobar", "bar", "barbaz");
    ensureGreen();
    assertAcked(client().admin().indices().prepareClose("_all").get());
    verify(client().admin().indices().prepareUpdateSettings("foo").setSettings(Settings.builder().put("a", "b")), false);
    verify(client().admin().indices().prepareUpdateSettings("bar*").setSettings(Settings.builder().put("a", "b")), false);
    verify(client().admin().indices().prepareUpdateSettings("_all").setSettings(Settings.builder().put("c", "d")), false);
    GetSettingsResponse settingsResponse = client().admin().indices().prepareGetSettings("foo").get();
    assertThat(settingsResponse.getSetting("foo", "index.a"), equalTo("b"));
    settingsResponse = client().admin().indices().prepareGetSettings("bar*").get();
    assertThat(settingsResponse.getSetting("bar", "index.a"), equalTo("b"));
    assertThat(settingsResponse.getSetting("barbaz", "index.a"), equalTo("b"));
    settingsResponse = client().admin().indices().prepareGetSettings("_all").get();
    assertThat(settingsResponse.getSetting("foo", "index.c"), equalTo("d"));
    assertThat(settingsResponse.getSetting("foobar", "index.c"), equalTo("d"));
    assertThat(settingsResponse.getSetting("bar", "index.c"), equalTo("d"));
    assertThat(settingsResponse.getSetting("barbaz", "index.c"), equalTo("d"));
    assertAcked(client().admin().indices().prepareOpen("_all").get());
    try {
        verify(client().admin().indices().prepareUpdateSettings("barbaz").setSettings(Settings.builder().put("e", "f")), false);
    } catch (IllegalArgumentException e) {
        assertThat(e.getMessage(), startsWith("Can't update non dynamic settings [[index.e]] for open indices [[barbaz"));
    }
    verify(client().admin().indices().prepareUpdateSettings("baz*").setSettings(Settings.builder().put("a", "b")), 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