Search in sources :

Example 11 with GetSettingsResponse

use of org.elasticsearch.action.admin.indices.settings.get.GetSettingsResponse in project graylog2-server by Graylog2.

the class IndicesAdapterES7 method indexCreationDate.

@Override
public Optional<DateTime> indexCreationDate(String index) {
    final GetSettingsRequest request = new GetSettingsRequest().indices(index).indicesOptions(IndicesOptions.fromOptions(true, true, true, false));
    final GetSettingsResponse result = client.execute((c, requestOptions) -> c.indices().getSettings(request, requestOptions), "Couldn't read settings of index " + index);
    final Optional<String> creationDate = Optional.ofNullable(result.getIndexToSettings().get(index)).map(indexSettings -> indexSettings.get("index.creation_date"));
    return creationDate.map(Long::valueOf).map(instant -> new DateTime(instant, DateTimeZone.UTC));
}
Also used : GetSettingsRequest(org.graylog.shaded.elasticsearch7.org.elasticsearch.action.admin.indices.settings.get.GetSettingsRequest) GetSettingsResponse(org.graylog.shaded.elasticsearch7.org.elasticsearch.action.admin.indices.settings.get.GetSettingsResponse) DateTime(org.joda.time.DateTime)

Example 12 with GetSettingsResponse

use of org.elasticsearch.action.admin.indices.settings.get.GetSettingsResponse in project elasticsearch by elastic.

the class RolloverIT method testRolloverWithDateMath.

public void testRolloverWithDateMath() {
    DateTime now = new DateTime(DateTimeZone.UTC);
    String index = "test-" + DateTimeFormat.forPattern("YYYY.MM.dd").print(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-" + DateTimeFormat.forPattern("YYYY.MM").print(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-" + DateTimeFormat.forPattern("YYYY.MM").print(now) + "-000002"));
    assertThat(response.getNewIndex(), equalTo("test-" + DateTimeFormat.forPattern("YYYY.MM").print(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-" + DateTimeFormat.forPattern("YYYY.MM").print(now) + "-000003"));
    assertThat(response.getNewIndex(), equalTo("test-" + DateTimeFormat.forPattern("YYYY.MM.dd").print(now) + "-000004"));
    assertThat(response.isDryRun(), equalTo(false));
    assertThat(response.isRolledOver(), equalTo(true));
    assertThat(response.getConditionStatus().size(), equalTo(0));
}
Also used : GetSettingsResponse(org.elasticsearch.action.admin.indices.settings.get.GetSettingsResponse) Alias(org.elasticsearch.action.admin.indices.alias.Alias) DateTime(org.joda.time.DateTime)

Example 13 with GetSettingsResponse

use of org.elasticsearch.action.admin.indices.settings.get.GetSettingsResponse in project elasticsearch by elastic.

the class SimpleIndexTemplateIT method testInvalidSettings.

public void testInvalidSettings() throws Exception {
    // clean all templates setup by the framework.
    client().admin().indices().prepareDeleteTemplate("*").get();
    // check get all templates on an empty index.
    GetIndexTemplatesResponse response = client().admin().indices().prepareGetTemplates().get();
    assertThat(response.getIndexTemplates(), empty());
    IllegalArgumentException e = expectThrows(IllegalArgumentException.class, () -> client().admin().indices().preparePutTemplate("template_1").setPatterns(Collections.singletonList("te*")).setSettings(Settings.builder().put("does_not_exist", "test")).get());
    assertEquals("unknown setting [index.does_not_exist] please check that any required plugins are" + " installed, or check the breaking changes documentation for removed settings", e.getMessage());
    response = client().admin().indices().prepareGetTemplates().get();
    assertEquals(0, response.getIndexTemplates().size());
    createIndex("test");
    GetSettingsResponse getSettingsResponse = client().admin().indices().prepareGetSettings("test").get();
    assertNull(getSettingsResponse.getIndexToSettings().get("test").getAsMap().get("index.does_not_exist"));
}
Also used : GetSettingsResponse(org.elasticsearch.action.admin.indices.settings.get.GetSettingsResponse) GetIndexTemplatesResponse(org.elasticsearch.action.admin.indices.template.get.GetIndexTemplatesResponse)

Example 14 with GetSettingsResponse

use of org.elasticsearch.action.admin.indices.settings.get.GetSettingsResponse in project elasticsearch by elastic.

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, "type", "1").setSource("{}", XContentType.JSON).get();
    client().prepareIndex(dateMathExp2, "type", "2").setSource("{}", XContentType.JSON).get();
    client().prepareIndex(dateMathExp3, "type", "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, "type", "1").get();
    assertThat(getResponse.isExists(), is(true));
    assertThat(getResponse.getId(), equalTo("1"));
    getResponse = client().prepareGet(dateMathExp2, "type", "2").get();
    assertThat(getResponse.isExists(), is(true));
    assertThat(getResponse.getId(), equalTo("2"));
    getResponse = client().prepareGet(dateMathExp3, "type", "3").get();
    assertThat(getResponse.isExists(), is(true));
    assertThat(getResponse.getId(), equalTo("3"));
    MultiGetResponse mgetResponse = client().prepareMultiGet().add(dateMathExp1, "type", "1").add(dateMathExp2, "type", "2").add(dateMathExp3, "type", "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, "type", "1").get();
    assertEquals(DocWriteResponse.Result.DELETED, deleteResponse.getResult());
    assertThat(deleteResponse.getId(), equalTo("1"));
    deleteResponse = client().prepareDelete(dateMathExp2, "type", "2").get();
    assertEquals(DocWriteResponse.Result.DELETED, deleteResponse.getResult());
    assertThat(deleteResponse.getId(), equalTo("2"));
    deleteResponse = client().prepareDelete(dateMathExp3, "type", "3").get();
    assertEquals(DocWriteResponse.Result.DELETED, deleteResponse.getResult());
    assertThat(deleteResponse.getId(), equalTo("3"));
}
Also used : MultiGetResponse(org.elasticsearch.action.get.MultiGetResponse) IndicesStatsResponse(org.elasticsearch.action.admin.indices.stats.IndicesStatsResponse) DeleteResponse(org.elasticsearch.action.delete.DeleteResponse) GetSettingsResponse(org.elasticsearch.action.admin.indices.settings.get.GetSettingsResponse) GetResponse(org.elasticsearch.action.get.GetResponse) MultiGetResponse(org.elasticsearch.action.get.MultiGetResponse) DateTime(org.joda.time.DateTime) SearchResponse(org.elasticsearch.action.search.SearchResponse)

Example 15 with GetSettingsResponse

use of org.elasticsearch.action.admin.indices.settings.get.GetSettingsResponse in project elasticsearch by elastic.

the class UpdateSettingsIT method testOpenCloseUpdateSettings.

public void testOpenCloseUpdateSettings() throws Exception {
    createIndex("test");
    try {
        client().admin().indices().prepareUpdateSettings("test").setSettings(Settings.builder().put("index.refresh_interval", // this one can change
        -1).put("index.fielddata.cache", // this one can't
        "none")).execute().actionGet();
        fail();
    } catch (IllegalArgumentException e) {
    // all is well
    }
    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());
    // 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());
    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", // this one can't
    "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"));
    // 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.fielddata.cache"), equalTo("none"));
}
Also used : ClusterHealthResponse(org.elasticsearch.action.admin.cluster.health.ClusterHealthResponse) GetSettingsResponse(org.elasticsearch.action.admin.indices.settings.get.GetSettingsResponse) IndexMetaData(org.elasticsearch.cluster.metadata.IndexMetaData)

Aggregations

GetSettingsResponse (org.elasticsearch.action.admin.indices.settings.get.GetSettingsResponse)17 Settings (org.elasticsearch.common.settings.Settings)4 DateTime (org.joda.time.DateTime)4 GetIndexTemplatesResponse (org.elasticsearch.action.admin.indices.template.get.GetIndexTemplatesResponse)3 Version (org.elasticsearch.Version)2 CreateSnapshotResponse (org.elasticsearch.action.admin.cluster.snapshots.create.CreateSnapshotResponse)2 RestoreSnapshotResponse (org.elasticsearch.action.admin.cluster.snapshots.restore.RestoreSnapshotResponse)2 GetSettingsRequest (org.elasticsearch.action.admin.indices.settings.get.GetSettingsRequest)2 SearchResponse (org.elasticsearch.action.search.SearchResponse)2 Client (org.elasticsearch.client.Client)2 ObjectObjectCursor (com.carrotsearch.hppc.cursors.ObjectObjectCursor)1 BasicConfiguration (com.thinkaurelius.titan.diskstorage.configuration.BasicConfiguration)1 Configuration (com.thinkaurelius.titan.diskstorage.configuration.Configuration)1 ModifiableConfiguration (com.thinkaurelius.titan.diskstorage.configuration.ModifiableConfiguration)1 CommonsConfiguration (com.thinkaurelius.titan.diskstorage.configuration.backend.CommonsConfiguration)1 ElasticSearchIndex (com.thinkaurelius.titan.diskstorage.es.ElasticSearchIndex)1 GraphDatabaseConfiguration (com.thinkaurelius.titan.graphdb.configuration.GraphDatabaseConfiguration)1 PartitionName (io.crate.metadata.PartitionName)1 IOException (java.io.IOException)1 BaseConfiguration (org.apache.commons.configuration.BaseConfiguration)1