Search in sources :

Example 6 with DeleteIndexRequest

use of org.elasticsearch.action.admin.indices.delete.DeleteIndexRequest in project ecs-dashboard by carone1.

the class ElasticVdcDetailDAO method initVdcIndex.

/**
 * @param collectionTime
 */
private void initVdcIndex(Date collectionTime) {
    String collectionDayString = DATA_DATE_FORMAT.format(collectionTime);
    vdcIndexDayName = VDC_INDEX_NAME + "-" + collectionDayString;
    if (elasticClient.admin().indices().exists(new IndicesExistsRequest(vdcIndexDayName)).actionGet().isExists()) {
        // Index already exists need to truncate it and recreate it
        DeleteIndexRequest deleteIndexRequest = new DeleteIndexRequest(vdcIndexDayName);
        ActionFuture<DeleteIndexResponse> futureResult = elasticClient.admin().indices().delete(deleteIndexRequest);
        // Wait until deletion is done
        while (!futureResult.isDone()) {
            try {
                Thread.sleep(100);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    }
    elasticClient.admin().indices().create(new CreateIndexRequest(vdcIndexDayName)).actionGet();
    try {
        PutMappingResponse putMappingResponse = elasticClient.admin().indices().preparePutMapping(vdcIndexDayName).setType(VDC_INDEX_TYPE).setSource(XContentFactory.jsonBuilder().prettyPrint().startObject().startObject(VDC_INDEX_TYPE).startObject("properties").startObject(VdcDetail.VDC_ID).field("type", "string").field("index", NOT_ANALYZED_INDEX).endObject().startObject(VdcDetail.VDC_NAME).field("type", "string").field("index", NOT_ANALYZED_INDEX).endObject().startObject(VdcDetail.INTER_VDC_END_POINTS).field("type", "string").field("index", NOT_ANALYZED_INDEX).endObject().startObject(VdcDetail.INTER_VDC_CMD_END_POINTS).field("type", "string").field("index", NOT_ANALYZED_INDEX).endObject().startObject(VdcDetail.SECRET_KEYS).field("type", "string").field("index", NOT_ANALYZED_INDEX).endObject().startObject(VdcDetail.PERMANENTLY_FAILED).field("type", "string").field("index", NOT_ANALYZED_INDEX).endObject().startObject(VdcDetail.LOCAL).field("type", "string").field("index", NOT_ANALYZED_INDEX).endObject().startObject(VdcDetail.MGMT_END_POINTS).field("type", "string").field("index", NOT_ANALYZED_INDEX).endObject().startObject(VdcDetail.NAME).field("type", "string").field("index", NOT_ANALYZED_INDEX).endObject().startObject(VdcDetail.ID).field("type", "string").field("index", NOT_ANALYZED_INDEX).endObject().startObject(VdcDetail.LINK).field("type", "string").field("index", NOT_ANALYZED_INDEX).endObject().startObject(VdcDetail.INACTIVE).field("type", "string").field("index", NOT_ANALYZED_INDEX).endObject().startObject(VdcDetail.GLOBAL).field("type", "string").field("index", NOT_ANALYZED_INDEX).endObject().startObject(VdcDetail.REMOTE).field("type", "string").field("index", NOT_ANALYZED_INDEX).endObject().startObject(VdcDetail.VDC).field("type", "string").field("index", NOT_ANALYZED_INDEX).endObject().startObject(VdcDetail.INTERNAL).field("type", "string").field("index", NOT_ANALYZED_INDEX).endObject().startObject(VdcDetail.CREATION_TIME).field("type", "date").field("format", "strict_date_optional_time||epoch_millis").field("index", NOT_ANALYZED_INDEX).endObject().startObject(VdcDetail.NAME + ANALYZED_TAG).field("type", "string").field("index", ANALYZED_INDEX).endObject().startObject(VdcDetail.VDC_NAME + ANALYZED_TAG).field("type", "string").field("index", ANALYZED_INDEX).endObject().startObject(COLLECTION_TIME).field("type", "date").field("format", "strict_date_optional_time||epoch_millis").endObject().endObject().startArray("dynamic_templates").startObject().startObject("notanalyzed").field("match", "*").field("match_mapping_type", "string").startObject("mapping").field("type", "string").field("index", NOT_ANALYZED_INDEX).endObject().endObject().endObject().endArray().endObject().endObject()).execute().actionGet();
        if (putMappingResponse.isAcknowledged()) {
            LOGGER.info("Index Created: " + vdcIndexDayName);
        } else {
            LOGGER.error("Index {" + vdcIndexDayName + "} did not exist. " + "While attempting to create the index in ElasticSearch " + "Templates we were unable to get an acknowledgement.", vdcIndexDayName);
            LOGGER.error("Error Message: {}", putMappingResponse.toString());
            throw new RuntimeException("Unable to create index " + vdcIndexDayName);
        }
    } catch (IOException e) {
        throw new RuntimeException("Unable to create index " + vdcIndexDayName + " " + e.getMessage());
    }
}
Also used : DeleteIndexResponse(org.elasticsearch.action.admin.indices.delete.DeleteIndexResponse) DeleteIndexRequest(org.elasticsearch.action.admin.indices.delete.DeleteIndexRequest) PutMappingResponse(org.elasticsearch.action.admin.indices.mapping.put.PutMappingResponse) IOException(java.io.IOException) CreateIndexRequest(org.elasticsearch.action.admin.indices.create.CreateIndexRequest) IndicesExistsRequest(org.elasticsearch.action.admin.indices.exists.indices.IndicesExistsRequest)

Example 7 with DeleteIndexRequest

use of org.elasticsearch.action.admin.indices.delete.DeleteIndexRequest in project vertexium by visallo.

the class Elasticsearch5SearchIndex method drop.

@Override
public void drop(Graph graph) {
    Set<String> indexInfosSet = new HashSet<>(getIndexInfos(graph).keySet());
    for (String indexName : indexInfosSet) {
        try {
            DeleteIndexRequest deleteRequest = new DeleteIndexRequest(indexName);
            getClient().admin().indices().delete(deleteRequest).actionGet();
            getIndexInfos(graph).remove(indexName);
        } catch (Exception ex) {
            throw new VertexiumException("Could not delete index " + indexName, ex);
        }
        ensureIndexCreatedAndInitialized(graph, indexName);
    }
}
Also used : DeleteIndexRequest(org.elasticsearch.action.admin.indices.delete.DeleteIndexRequest) NodeValidationException(org.elasticsearch.node.NodeValidationException) UnknownHostException(java.net.UnknownHostException)

Example 8 with DeleteIndexRequest

use of org.elasticsearch.action.admin.indices.delete.DeleteIndexRequest in project logging-log4j2 by apache.

the class LogstashIT method createClient.

private static RestHighLevelClient createClient() throws IOException {
    // Instantiate the client.
    LOGGER.info("instantiating the ES client");
    final HttpHost httpHost = new HttpHost(HOST_NAME, MavenHardcodedConstants.ES_PORT);
    final RestClientBuilder clientBuilder = RestClient.builder(httpHost);
    final RestHighLevelClient client = new RestHighLevelClient(clientBuilder);
    // Verify the connection.
    LOGGER.info("verifying the ES connection");
    final ClusterHealthResponse healthResponse = client.cluster().health(new ClusterHealthRequest(), RequestOptions.DEFAULT);
    Assertions.assertThat(healthResponse.getStatus()).isNotEqualTo(ClusterHealthStatus.RED);
    // Delete the index.
    LOGGER.info("deleting the ES index");
    final DeleteIndexRequest deleteRequest = new DeleteIndexRequest(MavenHardcodedConstants.ES_INDEX_NAME);
    try {
        final AcknowledgedResponse deleteResponse = client.indices().delete(deleteRequest, RequestOptions.DEFAULT);
        Assertions.assertThat(deleteResponse.isAcknowledged()).isTrue();
    } catch (ElasticsearchStatusException error) {
        Assertions.assertThat(error).satisfies(ignored -> Assertions.assertThat(error.status()).isEqualTo(RestStatus.NOT_FOUND));
    }
    return client;
}
Also used : SimpleMessage(org.apache.logging.log4j.message.SimpleMessage) Arrays(java.util.Arrays) RestClientBuilder(org.elasticsearch.client.RestClientBuilder) Level(org.apache.logging.log4j.Level) LogEvent(org.apache.logging.log4j.core.LogEvent) Duration(java.time.Duration) Map(java.util.Map) SearchResponse(org.elasticsearch.action.search.SearchResponse) RequestOptions(org.elasticsearch.client.RequestOptions) Assertions(org.assertj.core.api.Assertions) ElasticsearchStatusException(org.elasticsearch.ElasticsearchStatusException) Log4jLogEvent(org.apache.logging.log4j.core.impl.Log4jLogEvent) SearchHit(org.elasticsearch.search.SearchHit) ExecutionMode(org.junit.jupiter.api.parallel.ExecutionMode) Set(java.util.Set) Instant(java.time.Instant) Collectors(java.util.stream.Collectors) StandardCharsets(java.nio.charset.StandardCharsets) Test(org.junit.jupiter.api.Test) Objects(java.util.Objects) List(java.util.List) Stream(java.util.stream.Stream) ThreadLocalRecyclerFactory(org.apache.logging.log4j.layout.template.json.util.ThreadLocalRecyclerFactory) ClusterHealthRequest(org.elasticsearch.action.admin.cluster.health.ClusterHealthRequest) GelfLayout(org.apache.logging.log4j.core.layout.GelfLayout) RestStatus(org.elasticsearch.rest.RestStatus) Layout(org.apache.logging.log4j.core.Layout) Awaitility(org.awaitility.Awaitility) RestClient(org.elasticsearch.client.RestClient) DefaultConfiguration(org.apache.logging.log4j.core.config.DefaultConfiguration) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Appender(org.apache.logging.log4j.core.Appender) SearchRequest(org.elasticsearch.action.search.SearchRequest) Function(java.util.function.Function) EventTemplateAdditionalField(org.apache.logging.log4j.layout.template.json.JsonTemplateLayout.EventTemplateAdditionalField) NetUtils(org.apache.logging.log4j.core.util.NetUtils) Charset(java.nio.charset.Charset) SocketAppender(org.apache.logging.log4j.core.appender.SocketAppender) SearchSourceBuilder(org.elasticsearch.search.builder.SearchSourceBuilder) PrintStream(java.io.PrintStream) DeleteIndexRequest(org.elasticsearch.action.admin.indices.delete.DeleteIndexRequest) EcsLayout(co.elastic.logging.log4j2.EcsLayout) ClusterHealthResponse(org.elasticsearch.action.admin.cluster.health.ClusterHealthResponse) IOException(java.io.IOException) AcknowledgedResponse(org.elasticsearch.action.support.master.AcknowledgedResponse) RestHighLevelClient(org.elasticsearch.client.RestHighLevelClient) StatusLogger(org.apache.logging.log4j.status.StatusLogger) ClusterHealthStatus(org.elasticsearch.cluster.health.ClusterHealthStatus) Execution(org.junit.jupiter.api.parallel.Execution) HttpHost(org.apache.http.HttpHost) Collections(java.util.Collections) ClusterHealthResponse(org.elasticsearch.action.admin.cluster.health.ClusterHealthResponse) ClusterHealthRequest(org.elasticsearch.action.admin.cluster.health.ClusterHealthRequest) HttpHost(org.apache.http.HttpHost) AcknowledgedResponse(org.elasticsearch.action.support.master.AcknowledgedResponse) RestClientBuilder(org.elasticsearch.client.RestClientBuilder) DeleteIndexRequest(org.elasticsearch.action.admin.indices.delete.DeleteIndexRequest) RestHighLevelClient(org.elasticsearch.client.RestHighLevelClient) ElasticsearchStatusException(org.elasticsearch.ElasticsearchStatusException)

Example 9 with DeleteIndexRequest

use of org.elasticsearch.action.admin.indices.delete.DeleteIndexRequest in project crate by crate.

the class BlobAdminClient method dropBlobTable.

public CompletableFuture<Long> dropBlobTable(final String tableName) {
    FutureActionListener<AcknowledgedResponse, Long> listener = new FutureActionListener<>(r -> 1L);
    deleteIndexAction.execute(new DeleteIndexRequest(fullIndexName(tableName)), listener);
    return listener;
}
Also used : AcknowledgedResponse(org.elasticsearch.action.support.master.AcknowledgedResponse) DeleteIndexRequest(org.elasticsearch.action.admin.indices.delete.DeleteIndexRequest) FutureActionListener(io.crate.action.FutureActionListener)

Example 10 with DeleteIndexRequest

use of org.elasticsearch.action.admin.indices.delete.DeleteIndexRequest in project graylog2-server by Graylog2.

the class ClientES7 method deleteIndices.

@Override
public void deleteIndices(String... indices) {
    for (String index : indices) {
        if (indicesExists(index)) {
            final DeleteIndexRequest deleteIndexRequest = new DeleteIndexRequest(index);
            client.execute((c, requestOptions) -> c.indices().delete(deleteIndexRequest, requestOptions));
        }
    }
}
Also used : DeleteIndexRequest(org.graylog.shaded.elasticsearch7.org.elasticsearch.action.admin.indices.delete.DeleteIndexRequest)

Aggregations

DeleteIndexRequest (org.elasticsearch.action.admin.indices.delete.DeleteIndexRequest)37 IOException (java.io.IOException)15 DeleteIndexResponse (org.elasticsearch.action.admin.indices.delete.DeleteIndexResponse)15 CreateIndexRequest (org.elasticsearch.action.admin.indices.create.CreateIndexRequest)13 IndicesExistsRequest (org.elasticsearch.action.admin.indices.exists.indices.IndicesExistsRequest)12 PutMappingResponse (org.elasticsearch.action.admin.indices.mapping.put.PutMappingResponse)9 ArrayList (java.util.ArrayList)6 AcknowledgedResponse (org.elasticsearch.action.support.master.AcknowledgedResponse)6 List (java.util.List)5 Row1 (io.crate.data.Row1)3 OneRowActionListener (io.crate.execution.support.OneRowActionListener)3 BulkRequest (org.elasticsearch.action.bulk.BulkRequest)3 MultiGetRequest (org.elasticsearch.action.get.MultiGetRequest)3 MultiSearchRequest (org.elasticsearch.action.search.MultiSearchRequest)3 SearchRequest (org.elasticsearch.action.search.SearchRequest)3 FutureActionListener (io.crate.action.FutureActionListener)2 Row (io.crate.data.Row)2 RowConsumer (io.crate.data.RowConsumer)2 DependencyCarrier (io.crate.planner.DependencyCarrier)2 Plan (io.crate.planner.Plan)2