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());
}
}
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);
}
}
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;
}
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;
}
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));
}
}
}
Aggregations