Search in sources :

Example 1 with GetIndexResponse

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

the class OldIndexBackwardsCompatibilityIT method assertIndexSanity.

void assertIndexSanity(String indexName, Version indexCreated) {
    GetIndexResponse getIndexResponse = client().admin().indices().prepareGetIndex().addIndices(indexName).get();
    assertEquals(1, getIndexResponse.indices().length);
    assertEquals(indexName, getIndexResponse.indices()[0]);
    Version actualVersionCreated = Version.indexCreated(getIndexResponse.getSettings().get(indexName));
    assertEquals(indexCreated, actualVersionCreated);
    ensureYellow(indexName);
    RecoveryResponse recoveryResponse = client().admin().indices().prepareRecoveries(indexName).setDetailed(true).setActiveOnly(false).get();
    boolean foundTranslog = false;
    for (List<RecoveryState> states : recoveryResponse.shardRecoveryStates().values()) {
        for (RecoveryState state : states) {
            if (state.getStage() == RecoveryState.Stage.DONE && state.getPrimary() && state.getRecoverySource().getType() == RecoverySource.Type.EXISTING_STORE) {
                assertFalse("more than one primary recoverd?", foundTranslog);
                assertNotEquals(0, state.getTranslog().recoveredOperations());
                foundTranslog = true;
            }
        }
    }
    assertTrue("expected translog but nothing was recovered", foundTranslog);
    IndicesSegmentResponse segmentsResponse = client().admin().indices().prepareSegments(indexName).get();
    IndexSegments segments = segmentsResponse.getIndices().get(indexName);
    int numCurrent = 0;
    int numBWC = 0;
    for (IndexShardSegments indexShardSegments : segments) {
        for (ShardSegments shardSegments : indexShardSegments) {
            for (Segment segment : shardSegments) {
                if (indexCreated.luceneVersion.equals(segment.version)) {
                    numBWC++;
                    if (Version.CURRENT.luceneVersion.equals(segment.version)) {
                        numCurrent++;
                    }
                } else if (Version.CURRENT.luceneVersion.equals(segment.version)) {
                    numCurrent++;
                } else {
                    fail("unexpected version " + segment.version);
                }
            }
        }
    }
    assertNotEquals("expected at least 1 current segment after translog recovery", 0, numCurrent);
    assertNotEquals("expected at least 1 old segment", 0, numBWC);
    SearchResponse test = client().prepareSearch(indexName).get();
    assertThat(test.getHits().getTotalHits(), greaterThanOrEqualTo(1L));
}
Also used : IndicesSegmentResponse(org.elasticsearch.action.admin.indices.segments.IndicesSegmentResponse) IndexShardSegments(org.elasticsearch.action.admin.indices.segments.IndexShardSegments) IndexSegments(org.elasticsearch.action.admin.indices.segments.IndexSegments) Segment(org.elasticsearch.index.engine.Segment) RecoveryResponse(org.elasticsearch.action.admin.indices.recovery.RecoveryResponse) SearchResponse(org.elasticsearch.action.search.SearchResponse) Version(org.elasticsearch.Version) GetIndexResponse(org.elasticsearch.action.admin.indices.get.GetIndexResponse) ShardSegments(org.elasticsearch.action.admin.indices.segments.ShardSegments) IndexShardSegments(org.elasticsearch.action.admin.indices.segments.IndexShardSegments) RecoveryState(org.elasticsearch.indices.recovery.RecoveryState)

Example 2 with GetIndexResponse

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

the class DynamicMappingIT method testAutoCreateWithDisabledDynamicMappings.

public void testAutoCreateWithDisabledDynamicMappings() throws Exception {
    assertAcked(client().admin().indices().preparePutTemplate("my_template").setCreate(true).setPatterns(Collections.singletonList("index_*")).addMapping("foo", "field", "type=keyword").setSettings(Settings.builder().put("index.mapper.dynamic", false).build()).get());
    // succeeds since 'foo' has an explicit mapping in the template
    indexRandom(true, false, client().prepareIndex("index_1", "foo", "1").setSource("field", "abc"));
    // fails since 'bar' does not have an explicit mapping in the template and dynamic template creation is disabled
    TypeMissingException e1 = expectThrows(TypeMissingException.class, () -> client().prepareIndex("index_2", "bar", "1").setSource("field", "abc").get());
    assertEquals("type[bar] missing", e1.getMessage());
    assertEquals("trying to auto create mapping, but dynamic mapping is disabled", e1.getCause().getMessage());
    // make sure no mappings were created for bar
    GetIndexResponse getIndexResponse = client().admin().indices().prepareGetIndex().addIndices("index_2").get();
    assertFalse(getIndexResponse.mappings().containsKey("bar"));
}
Also used : TypeMissingException(org.elasticsearch.indices.TypeMissingException) GetIndexResponse(org.elasticsearch.action.admin.indices.get.GetIndexResponse)

Example 3 with GetIndexResponse

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

the class ESSingleNodeTestCase method resolveIndex.

public Index resolveIndex(String index) {
    GetIndexResponse getIndexResponse = client().admin().indices().prepareGetIndex().setIndices(index).get();
    assertTrue("index " + index + " not found", getIndexResponse.getSettings().containsKey(index));
    String uuid = getIndexResponse.getSettings().get(index).get(IndexMetaData.SETTING_INDEX_UUID);
    return new Index(index, uuid);
}
Also used : GetIndexResponse(org.elasticsearch.action.admin.indices.get.GetIndexResponse) Index(org.elasticsearch.index.Index)

Example 4 with GetIndexResponse

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

the class ESIntegTestCase method resolveIndex.

public static Index resolveIndex(String index) {
    GetIndexResponse getIndexResponse = client().admin().indices().prepareGetIndex().setIndices(index).get();
    assertTrue("index " + index + " not found", getIndexResponse.getSettings().containsKey(index));
    String uuid = getIndexResponse.getSettings().get(index).get(IndexMetaData.SETTING_INDEX_UUID);
    return new Index(index, uuid);
}
Also used : GetIndexResponse(org.elasticsearch.action.admin.indices.get.GetIndexResponse) Index(org.elasticsearch.index.Index)

Example 5 with GetIndexResponse

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

the class Indices method indexCreationDate.

@Nullable
public DateTime indexCreationDate(String index) {
    final GetIndexRequest indexRequest = c.admin().indices().prepareGetIndex().addFeatures(GetIndexRequest.Feature.SETTINGS).addIndices(index).request();
    try {
        final GetIndexResponse response = c.admin().indices().getIndex(indexRequest).actionGet();
        final Settings settings = response.settings().get(index);
        if (settings == null) {
            return null;
        }
        return new DateTime(settings.getAsLong("index.creation_date", 0L), DateTimeZone.UTC);
    } catch (ElasticsearchException e) {
        LOG.warn("Unable to read creation_date for index " + index, e.getRootCause());
        return null;
    }
}
Also used : GetIndexResponse(org.elasticsearch.action.admin.indices.get.GetIndexResponse) GetIndexRequest(org.elasticsearch.action.admin.indices.get.GetIndexRequest) ElasticsearchException(org.elasticsearch.ElasticsearchException) Settings(org.elasticsearch.common.settings.Settings) DateTime(org.joda.time.DateTime) Nullable(javax.annotation.Nullable)

Aggregations

GetIndexResponse (org.elasticsearch.action.admin.indices.get.GetIndexResponse)12 Settings (org.elasticsearch.common.settings.Settings)3 List (java.util.List)2 Set (java.util.Set)2 FessConfig (org.codelibs.fess.mylasta.direction.FessConfig)2 IndicesAliasesRequestBuilder (org.elasticsearch.action.admin.indices.alias.IndicesAliasesRequestBuilder)2 GetIndexRequest (org.elasticsearch.action.admin.indices.get.GetIndexRequest)2 GetIndexRequestBuilder (org.elasticsearch.action.admin.indices.get.GetIndexRequestBuilder)2 SearchResponse (org.elasticsearch.action.search.SearchResponse)2 IndicesAdminClient (org.elasticsearch.client.IndicesAdminClient)2 AliasMetaData (org.elasticsearch.cluster.metadata.AliasMetaData)2 Index (org.elasticsearch.index.Index)2 ObjectObjectCursor (com.carrotsearch.hppc.cursors.ObjectObjectCursor)1 ImmutableList (com.google.common.collect.ImmutableList)1 ImmutableSet (com.google.common.collect.ImmutableSet)1 File (java.io.File)1 IOException (java.io.IOException)1 Collectors.toSet (java.util.stream.Collectors.toSet)1 Nullable (javax.annotation.Nullable)1 PostConstruct (javax.annotation.PostConstruct)1