Search in sources :

Example 6 with IndicesExistsResponse

use of org.elasticsearch.action.admin.indices.exists.indices.IndicesExistsResponse in project graylog2-server by Graylog2.

the class IndicesGetAllMessageFieldsTest method GetAllMessageFieldsForIndicesForNonexistingIndexShouldReturnEmptySet.

@Test
@UsingDataSet(loadStrategy = LoadStrategyEnum.DELETE_ALL)
public void GetAllMessageFieldsForIndicesForNonexistingIndexShouldReturnEmptySet() throws Exception {
    final String[] indexNames = new String[] { "graylog_0" };
    final IndicesExistsResponse response = client.admin().indices().exists(new IndicesExistsRequest("graylog_0")).get();
    assertThat(response.isExists()).isFalse();
    final Map<String, Set<String>> result = indices.getAllMessageFieldsForIndices(indexNames);
    assertThat(result).isNotNull().isEmpty();
}
Also used : Set(java.util.Set) UsingDataSet(com.lordofthejars.nosqlunit.annotation.UsingDataSet) IndicesExistsResponse(org.elasticsearch.action.admin.indices.exists.indices.IndicesExistsResponse) IndicesExistsRequest(org.elasticsearch.action.admin.indices.exists.indices.IndicesExistsRequest) UsingDataSet(com.lordofthejars.nosqlunit.annotation.UsingDataSet) Test(org.junit.Test)

Example 7 with IndicesExistsResponse

use of org.elasticsearch.action.admin.indices.exists.indices.IndicesExistsResponse in project graylog2-server by Graylog2.

the class IndexCreatingDatabaseOperation method insert.

@Override
public void insert(InputStream dataScript) {
    waitForGreenStatus();
    final IndicesAdminClient indicesAdminClient = client.admin().indices();
    for (String index : indexes) {
        final IndicesExistsResponse indicesExistsResponse = indicesAdminClient.prepareExists(index).execute().actionGet();
        if (indicesExistsResponse.isExists()) {
            client.admin().indices().prepareDelete(index).execute().actionGet();
        }
        final Messages messages = new Messages(client, new MetricRegistry());
        final Indices indices = new Indices(client, new IndexMapping(), messages, mock(NodeId.class), new NullAuditEventSender());
        if (!indices.create(index, indexSet)) {
            throw new IllegalStateException("Couldn't create index " + index);
        }
    }
    databaseOperation.insert(dataScript);
}
Also used : NullAuditEventSender(org.graylog2.audit.NullAuditEventSender) IndexMapping(org.graylog2.indexer.IndexMapping) Messages(org.graylog2.indexer.messages.Messages) MetricRegistry(com.codahale.metrics.MetricRegistry) IndicesExistsResponse(org.elasticsearch.action.admin.indices.exists.indices.IndicesExistsResponse) NodeId(org.graylog2.plugin.system.NodeId) Indices(org.graylog2.indexer.indices.Indices) IndicesAdminClient(org.elasticsearch.client.IndicesAdminClient)

Example 8 with IndicesExistsResponse

use of org.elasticsearch.action.admin.indices.exists.indices.IndicesExistsResponse in project beam by apache.

the class ElasticSearchIOTestUtils method deleteIndex.

/** Deletes the given index synchronously. */
static void deleteIndex(String index, Client client) throws Exception {
    IndicesAdminClient indices = client.admin().indices();
    IndicesExistsResponse indicesExistsResponse = indices.exists(new IndicesExistsRequest(index)).get();
    if (indicesExistsResponse.isExists()) {
        indices.prepareClose(index).get();
        indices.delete(Requests.deleteIndexRequest(index)).get();
    }
}
Also used : IndicesExistsResponse(org.elasticsearch.action.admin.indices.exists.indices.IndicesExistsResponse) IndicesAdminClient(org.elasticsearch.client.IndicesAdminClient) IndicesExistsRequest(org.elasticsearch.action.admin.indices.exists.indices.IndicesExistsRequest)

Example 9 with IndicesExistsResponse

use of org.elasticsearch.action.admin.indices.exists.indices.IndicesExistsResponse in project fess by codelibs.

the class FessEsClient method existsIndex.

public boolean existsIndex(final String indexName) {
    final FessConfig fessConfig = ComponentUtil.getFessConfig();
    boolean exists = false;
    try {
        final IndicesExistsResponse response = client.admin().indices().prepareExists(indexName).execute().actionGet(fessConfig.getIndexSearchTimeout());
        exists = response.isExists();
    } catch (final Exception e) {
    // ignore
    }
    return exists;
}
Also used : IndicesExistsResponse(org.elasticsearch.action.admin.indices.exists.indices.IndicesExistsResponse) FessConfig(org.codelibs.fess.mylasta.direction.FessConfig) IllegalBehaviorStateException(org.dbflute.exception.IllegalBehaviorStateException) FessSystemException(org.codelibs.fess.exception.FessSystemException) ResultOffsetExceededException(org.codelibs.fess.exception.ResultOffsetExceededException) ResourceNotFoundRuntimeException(org.codelibs.core.exception.ResourceNotFoundRuntimeException) IOException(java.io.IOException) UnknownHostException(java.net.UnknownHostException) ElasticsearchException(org.elasticsearch.ElasticsearchException) SearchPhaseExecutionException(org.elasticsearch.action.search.SearchPhaseExecutionException) SearchQueryException(org.codelibs.fess.exception.SearchQueryException) InvalidQueryException(org.codelibs.fess.exception.InvalidQueryException)

Example 10 with IndicesExistsResponse

use of org.elasticsearch.action.admin.indices.exists.indices.IndicesExistsResponse in project play2-elasticsearch by cleverage.

the class IndexService method existsIndex.

/**
     * Test if an indice Exists
     * @return true if exists
     */
public static boolean existsIndex(String indexName) {
    Client client = IndexClient.client;
    AdminClient admin = client.admin();
    IndicesAdminClient indices = admin.indices();
    IndicesExistsRequestBuilder indicesExistsRequestBuilder = indices.prepareExists(indexName);
    IndicesExistsResponse response = indicesExistsRequestBuilder.execute().actionGet();
    return response.isExists();
}
Also used : IndicesExistsRequestBuilder(org.elasticsearch.action.admin.indices.exists.indices.IndicesExistsRequestBuilder) IndicesExistsResponse(org.elasticsearch.action.admin.indices.exists.indices.IndicesExistsResponse) IndicesAdminClient(org.elasticsearch.client.IndicesAdminClient) Client(org.elasticsearch.client.Client) IndicesAdminClient(org.elasticsearch.client.IndicesAdminClient) AdminClient(org.elasticsearch.client.AdminClient) IndicesAdminClient(org.elasticsearch.client.IndicesAdminClient) AdminClient(org.elasticsearch.client.AdminClient)

Aggregations

IndicesExistsResponse (org.elasticsearch.action.admin.indices.exists.indices.IndicesExistsResponse)10 IndicesExistsRequest (org.elasticsearch.action.admin.indices.exists.indices.IndicesExistsRequest)4 Test (org.junit.Test)4 IndicesAdminClient (org.elasticsearch.client.IndicesAdminClient)3 UsingDataSet (com.lordofthejars.nosqlunit.annotation.UsingDataSet)2 SQLTransportIntegrationTest (io.crate.integrationtests.SQLTransportIntegrationTest)2 MetricRegistry (com.codahale.metrics.MetricRegistry)1 TitanException (com.thinkaurelius.titan.core.TitanException)1 IOException (java.io.IOException)1 UnknownHostException (java.net.UnknownHostException)1 Set (java.util.Set)1 ResourceNotFoundRuntimeException (org.codelibs.core.exception.ResourceNotFoundRuntimeException)1 FessSystemException (org.codelibs.fess.exception.FessSystemException)1 InvalidQueryException (org.codelibs.fess.exception.InvalidQueryException)1 ResultOffsetExceededException (org.codelibs.fess.exception.ResultOffsetExceededException)1 SearchQueryException (org.codelibs.fess.exception.SearchQueryException)1 FessConfig (org.codelibs.fess.mylasta.direction.FessConfig)1 IllegalBehaviorStateException (org.dbflute.exception.IllegalBehaviorStateException)1 ElasticsearchException (org.elasticsearch.ElasticsearchException)1 CreateIndexResponse (org.elasticsearch.action.admin.indices.create.CreateIndexResponse)1