use of org.graylog.shaded.elasticsearch7.org.elasticsearch.action.admin.indices.delete.DeleteIndexRequest in project crate by crate.
the class DropTableTask method deleteESIndex.
private void deleteESIndex(String indexOrAlias, final BatchConsumer consumer) {
DeleteIndexRequest deleteIndexRequest = new DeleteIndexRequest(indexOrAlias);
if (tableInfo.isPartitioned()) {
deleteIndexRequest.indicesOptions(IndicesOptions.lenientExpandOpen());
}
deleteIndexAction.execute(deleteIndexRequest, new ActionListener<DeleteIndexResponse>() {
@Override
public void onResponse(DeleteIndexResponse response) {
if (!response.isAcknowledged()) {
warnNotAcknowledged();
}
consumer.accept(RowsBatchIterator.newInstance(ROW_ONE), null);
}
@Override
public void onFailure(Throwable e) {
if (tableInfo.isPartitioned()) {
logger.warn("Could not (fully) delete all partitions of {}. " + "Some orphaned partitions might still exist, " + "but are not accessible.", e, tableInfo.ident().fqn());
}
if (ifExists && e instanceof IndexNotFoundException) {
consumer.accept(RowsBatchIterator.newInstance(ROW_ZERO), null);
} else {
consumer.accept(null, e);
}
}
});
}
use of org.graylog.shaded.elasticsearch7.org.elasticsearch.action.admin.indices.delete.DeleteIndexRequest in project elasticsearch by elastic.
the class IndicesRequestIT method testDeleteIndex.
public void testDeleteIndex() {
interceptTransportActions(DeleteIndexAction.NAME);
String[] randomIndicesOrAliases = randomUniqueIndicesOrAliases();
DeleteIndexRequest deleteIndexRequest = new DeleteIndexRequest(randomIndicesOrAliases);
assertAcked(internalCluster().coordOnlyNodeClient().admin().indices().delete(deleteIndexRequest).actionGet());
clearInterceptedActions();
assertSameIndices(deleteIndexRequest, DeleteIndexAction.NAME);
}
use of org.graylog.shaded.elasticsearch7.org.elasticsearch.action.admin.indices.delete.DeleteIndexRequest in project crate by crate.
the class TableCreator method deleteOrphans.
private void deleteOrphans(final CreateTableResponseListener listener, final CreateTableAnalyzedStatement statement) {
if (clusterService.state().metaData().hasAlias(statement.tableIdent().fqn()) && PartitionName.isPartition(clusterService.state().metaData().getAliasAndIndexLookup().get(statement.tableIdent().fqn()).getIndices().iterator().next().getIndex())) {
logger.debug("Deleting orphaned partitions with alias: {}", statement.tableIdent().fqn());
transportActionProvider.transportDeleteIndexAction().execute(new DeleteIndexRequest(statement.tableIdent().fqn()), new ActionListener<DeleteIndexResponse>() {
@Override
public void onResponse(DeleteIndexResponse response) {
if (!response.isAcknowledged()) {
warnNotAcknowledged("deleting orphaned alias");
}
deleteOrphanedPartitions(listener, statement.tableIdent());
}
@Override
public void onFailure(Throwable e) {
listener.onFailure(e);
}
});
} else {
deleteOrphanedPartitions(listener, statement.tableIdent());
}
}
use of org.graylog.shaded.elasticsearch7.org.elasticsearch.action.admin.indices.delete.DeleteIndexRequest in project camel by apache.
the class ElasticsearchProducer method process.
public void process(Exchange exchange) throws Exception {
// 2. Index and type will be set by:
// a. If the incoming body is already an action request
// b. If the body is not an action request we will use headers if they
// are set.
// c. If the body is not an action request and the headers aren't set we
// will use the configuration.
// No error is thrown by the component in the event none of the above
// conditions are met. The java es client
// will throw.
Message message = exchange.getIn();
final ElasticsearchOperation operation = resolveOperation(exchange);
// Set the index/type headers on the exchange if necessary. This is used
// for type conversion.
boolean configIndexName = false;
String indexName = message.getHeader(ElasticsearchConstants.PARAM_INDEX_NAME, String.class);
if (indexName == null) {
message.setHeader(ElasticsearchConstants.PARAM_INDEX_NAME, configuration.getIndexName());
configIndexName = true;
}
boolean configIndexType = false;
String indexType = message.getHeader(ElasticsearchConstants.PARAM_INDEX_TYPE, String.class);
if (indexType == null) {
message.setHeader(ElasticsearchConstants.PARAM_INDEX_TYPE, configuration.getIndexType());
configIndexType = true;
}
boolean configWaitForActiveShards = false;
Integer waitForActiveShards = message.getHeader(ElasticsearchConstants.PARAM_WAIT_FOR_ACTIVE_SHARDS, Integer.class);
if (waitForActiveShards == null) {
message.setHeader(ElasticsearchConstants.PARAM_WAIT_FOR_ACTIVE_SHARDS, configuration.getWaitForActiveShards());
configWaitForActiveShards = true;
}
if (operation == ElasticsearchOperation.INDEX) {
IndexRequest indexRequest = message.getBody(IndexRequest.class);
message.setBody(client.index(indexRequest).actionGet().getId());
} else if (operation == ElasticsearchOperation.UPDATE) {
UpdateRequest updateRequest = message.getBody(UpdateRequest.class);
message.setBody(client.update(updateRequest).actionGet().getId());
} else if (operation == ElasticsearchOperation.GET_BY_ID) {
GetRequest getRequest = message.getBody(GetRequest.class);
message.setBody(client.get(getRequest));
} else if (operation == ElasticsearchOperation.MULTIGET) {
MultiGetRequest multiGetRequest = message.getBody(MultiGetRequest.class);
message.setBody(client.multiGet(multiGetRequest));
} else if (operation == ElasticsearchOperation.BULK) {
BulkRequest bulkRequest = message.getBody(BulkRequest.class);
message.setBody(client.bulk(bulkRequest).actionGet());
} else if (operation == ElasticsearchOperation.BULK_INDEX) {
BulkRequest bulkRequest = message.getBody(BulkRequest.class);
List<String> indexedIds = new ArrayList<String>();
for (BulkItemResponse response : client.bulk(bulkRequest).actionGet().getItems()) {
indexedIds.add(response.getId());
}
message.setBody(indexedIds);
} else if (operation == ElasticsearchOperation.DELETE) {
DeleteRequest deleteRequest = message.getBody(DeleteRequest.class);
message.setBody(client.delete(deleteRequest).actionGet());
} else if (operation == ElasticsearchOperation.EXISTS) {
// ExistsRequest API is deprecated, using SearchRequest instead with size=0 and terminate_after=1
SearchRequest searchRequest = new SearchRequest(exchange.getIn().getHeader(ElasticsearchConstants.PARAM_INDEX_NAME, String.class));
try {
client.prepareSearch(searchRequest.indices()).setSize(0).setTerminateAfter(1).get();
message.setBody(true);
} catch (IndexNotFoundException e) {
message.setBody(false);
}
} else if (operation == ElasticsearchOperation.SEARCH) {
SearchRequest searchRequest = message.getBody(SearchRequest.class);
message.setBody(client.search(searchRequest).actionGet());
} else if (operation == ElasticsearchOperation.MULTISEARCH) {
MultiSearchRequest multiSearchRequest = message.getBody(MultiSearchRequest.class);
message.setBody(client.multiSearch(multiSearchRequest));
} else if (operation == ElasticsearchOperation.DELETE_INDEX) {
DeleteIndexRequest deleteIndexRequest = message.getBody(DeleteIndexRequest.class);
message.setBody(client.admin().indices().delete(deleteIndexRequest).actionGet());
} else {
throw new IllegalArgumentException(ElasticsearchConstants.PARAM_OPERATION + " value '" + operation + "' is not supported");
}
// subsequent endpoint index/type with the first endpoint index/type.
if (configIndexName) {
message.removeHeader(ElasticsearchConstants.PARAM_INDEX_NAME);
}
if (configIndexType) {
message.removeHeader(ElasticsearchConstants.PARAM_INDEX_TYPE);
}
if (configWaitForActiveShards) {
message.removeHeader(ElasticsearchConstants.PARAM_WAIT_FOR_ACTIVE_SHARDS);
}
}
use of org.graylog.shaded.elasticsearch7.org.elasticsearch.action.admin.indices.delete.DeleteIndexRequest in project camel by apache.
the class ElasticsearchProducer method process.
public void process(Exchange exchange) throws Exception {
// 2. Index and type will be set by:
// a. If the incoming body is already an action request
// b. If the body is not an action request we will use headers if they
// are set.
// c. If the body is not an action request and the headers aren't set we
// will use the configuration.
// No error is thrown by the component in the event none of the above
// conditions are met. The java es client
// will throw.
Message message = exchange.getIn();
final String operation = resolveOperation(exchange);
// Set the index/type headers on the exchange if necessary. This is used
// for type conversion.
boolean configIndexName = false;
String indexName = message.getHeader(ElasticsearchConstants.PARAM_INDEX_NAME, String.class);
if (indexName == null) {
message.setHeader(ElasticsearchConstants.PARAM_INDEX_NAME, getEndpoint().getConfig().getIndexName());
configIndexName = true;
}
boolean configIndexType = false;
String indexType = message.getHeader(ElasticsearchConstants.PARAM_INDEX_TYPE, String.class);
if (indexType == null) {
message.setHeader(ElasticsearchConstants.PARAM_INDEX_TYPE, getEndpoint().getConfig().getIndexType());
configIndexType = true;
}
boolean configConsistencyLevel = false;
String consistencyLevel = message.getHeader(ElasticsearchConstants.PARAM_CONSISTENCY_LEVEL, String.class);
if (consistencyLevel == null) {
message.setHeader(ElasticsearchConstants.PARAM_CONSISTENCY_LEVEL, getEndpoint().getConfig().getConsistencyLevel());
configConsistencyLevel = true;
}
Client client = getEndpoint().getClient();
if (ElasticsearchConstants.OPERATION_INDEX.equals(operation)) {
IndexRequest indexRequest = message.getBody(IndexRequest.class);
message.setBody(client.index(indexRequest).actionGet().getId());
} else if (ElasticsearchConstants.OPERATION_UPDATE.equals(operation)) {
UpdateRequest updateRequest = message.getBody(UpdateRequest.class);
message.setBody(client.update(updateRequest).actionGet().getId());
} else if (ElasticsearchConstants.OPERATION_GET_BY_ID.equals(operation)) {
GetRequest getRequest = message.getBody(GetRequest.class);
message.setBody(client.get(getRequest));
} else if (ElasticsearchConstants.OPERATION_MULTIGET.equals(operation)) {
MultiGetRequest multiGetRequest = message.getBody(MultiGetRequest.class);
message.setBody(client.multiGet(multiGetRequest));
} else if (ElasticsearchConstants.OPERATION_BULK.equals(operation)) {
BulkRequest bulkRequest = message.getBody(BulkRequest.class);
message.setBody(client.bulk(bulkRequest).actionGet());
} else if (ElasticsearchConstants.OPERATION_BULK_INDEX.equals(operation)) {
BulkRequest bulkRequest = message.getBody(BulkRequest.class);
List<String> indexedIds = new ArrayList<String>();
for (BulkItemResponse response : client.bulk(bulkRequest).actionGet().getItems()) {
indexedIds.add(response.getId());
}
message.setBody(indexedIds);
} else if (ElasticsearchConstants.OPERATION_DELETE.equals(operation)) {
DeleteRequest deleteRequest = message.getBody(DeleteRequest.class);
message.setBody(client.delete(deleteRequest).actionGet());
} else if (ElasticsearchConstants.OPERATION_EXISTS.equals(operation)) {
ExistsRequest existsRequest = message.getBody(ExistsRequest.class);
message.setBody(client.admin().indices().prepareExists(existsRequest.indices()).get().isExists());
} else if (ElasticsearchConstants.OPERATION_SEARCH.equals(operation)) {
SearchRequest searchRequest = message.getBody(SearchRequest.class);
message.setBody(client.search(searchRequest).actionGet());
} else if (ElasticsearchConstants.OPERATION_MULTISEARCH.equals(operation)) {
MultiSearchRequest multiSearchRequest = message.getBody(MultiSearchRequest.class);
message.setBody(client.multiSearch(multiSearchRequest));
} else if (ElasticsearchConstants.OPERATION_DELETE_INDEX.equals(operation)) {
DeleteIndexRequest deleteIndexRequest = message.getBody(DeleteIndexRequest.class);
message.setBody(client.admin().indices().delete(deleteIndexRequest).actionGet());
} else {
throw new IllegalArgumentException(ElasticsearchConstants.PARAM_OPERATION + " value '" + operation + "' is not supported");
}
// subsequent endpoint index/type with the first endpoint index/type.
if (configIndexName) {
message.removeHeader(ElasticsearchConstants.PARAM_INDEX_NAME);
}
if (configIndexType) {
message.removeHeader(ElasticsearchConstants.PARAM_INDEX_TYPE);
}
if (configConsistencyLevel) {
message.removeHeader(ElasticsearchConstants.PARAM_CONSISTENCY_LEVEL);
}
}
Aggregations