use of org.elasticsearch.action.admin.indices.upgrade.post.UpgradeRequest in project elasticsearch by elastic.
the class RestUpgradeAction method handlePost.
private RestChannelConsumer handlePost(final RestRequest request, NodeClient client) {
UpgradeRequest upgradeReq = new UpgradeRequest(Strings.splitStringByCommaToArray(request.param("index")));
upgradeReq.indicesOptions(IndicesOptions.fromRequest(request, upgradeReq.indicesOptions()));
upgradeReq.upgradeOnlyAncientSegments(request.paramAsBoolean("only_ancient_segments", false));
return channel -> client.admin().indices().upgrade(upgradeReq, new RestBuilderListener<UpgradeResponse>(channel) {
@Override
public RestResponse buildResponse(UpgradeResponse response, XContentBuilder builder) throws Exception {
builder.startObject();
buildBroadcastShardsHeader(builder, request, response);
builder.startObject("upgraded_indices");
for (Map.Entry<String, Tuple<Version, String>> entry : response.versions().entrySet()) {
builder.startObject(entry.getKey());
builder.field("upgrade_version", entry.getValue().v1());
builder.field("oldest_lucene_segment_version", entry.getValue().v2());
builder.endObject();
}
builder.endObject();
builder.endObject();
return new BytesRestResponse(OK, builder);
}
});
}
use of org.elasticsearch.action.admin.indices.upgrade.post.UpgradeRequest in project crate by crate.
the class DDLStatementDispatcher method executeUpgradeSegments.
private static CompletableFuture<Long> executeUpgradeSegments(OptimizeTableAnalyzedStatement analysis, TransportUpgradeAction transportUpgradeAction) {
UpgradeRequest request = new UpgradeRequest(analysis.indexNames().toArray(new String[0]));
FutureActionListener<UpgradeResponse, Long> listener = new FutureActionListener<>(Functions.constant((long) analysis.indexNames().size()));
transportUpgradeAction.execute(request, listener);
return listener;
}
use of org.elasticsearch.action.admin.indices.upgrade.post.UpgradeRequest in project beam by apache.
the class ElasticSearchIOTestUtils method upgradeIndexAndGetCurrentNumDocs.
/**
* Forces an upgrade of the given index to make recently inserted documents available for search.
*
* @return The number of docs in the index
*/
static long upgradeIndexAndGetCurrentNumDocs(String index, String type, Client client) {
try {
client.admin().indices().upgrade(new UpgradeRequest(index)).actionGet();
SearchResponse response = client.prepareSearch(index).setTypes(type).execute().actionGet(5000);
return response.getHits().getTotalHits();
// it is fine to ignore bellow exceptions because in testWriteWithBatchSize* sometimes,
// we call upgrade before any doc have been written
// (when there are fewer docs processed than batchSize).
// In that cases index/type has not been created (created upon first doc insertion)
} catch (IndexNotFoundException e) {
} catch (java.lang.IllegalArgumentException e) {
if (!e.getMessage().contains("No search type")) {
throw e;
}
}
return 0;
}
use of org.elasticsearch.action.admin.indices.upgrade.post.UpgradeRequest in project components by Talend.
the class ElasticsearchTestUtils method upgradeIndexAndGetCurrentNumDocs.
/**
* Force an upgrade of all indices to make recently inserted documents available for search.
*
* @param client Elasticsearch TCP client to use for upgrade
* @return The number of docs in the index
*/
static long upgradeIndexAndGetCurrentNumDocs(String index, String type, Client client) {
try {
client.admin().indices().upgrade(new UpgradeRequest(index)).actionGet();
SearchResponse response = client.prepareSearch(index).setTypes(type).execute().actionGet(5000);
return response.getHits().getTotalHits();
// it is fine to ignore bellow exceptions because in testWriteWithBatchSize* sometimes,
// we call upgrade before any doc have been written
// (when there are fewer docs processed than batchSize).
// In that cases index/type has not been created (created upon first doc insertion)
} catch (IndexNotFoundException e) {
} catch (java.lang.IllegalArgumentException e) {
if (!e.getMessage().contains("No search type")) {
throw e;
}
}
return 0;
}
use of org.elasticsearch.action.admin.indices.upgrade.post.UpgradeRequest in project ranger by apache.
the class RequestUtils method getIndexFromRequest.
// To support all kinds of request in elasticsearch
public static <Request extends ActionRequest> List<String> getIndexFromRequest(Request request) {
List<String> indexs = new ArrayList<>();
if (request instanceof SingleShardRequest) {
indexs.add(((SingleShardRequest<?>) request).index());
return indexs;
}
if (request instanceof ReplicationRequest) {
indexs.add(((ReplicationRequest<?>) request).index());
return indexs;
}
if (request instanceof InstanceShardOperationRequest) {
indexs.add(((InstanceShardOperationRequest<?>) request).index());
return indexs;
}
if (request instanceof CreateIndexRequest) {
indexs.add(((CreateIndexRequest) request).index());
return indexs;
}
if (request instanceof PutMappingRequest) {
if (((PutMappingRequest) request).getConcreteIndex() != null) {
indexs.add(((PutMappingRequest) request).getConcreteIndex().getName());
return indexs;
} else {
return Arrays.asList(((PutMappingRequest) request).indices());
}
}
if (request instanceof SearchRequest) {
return Arrays.asList(((SearchRequest) request).indices());
}
if (request instanceof IndicesStatsRequest) {
return Arrays.asList(((IndicesStatsRequest) request).indices());
}
if (request instanceof OpenIndexRequest) {
return Arrays.asList(((OpenIndexRequest) request).indices());
}
if (request instanceof DeleteIndexRequest) {
return Arrays.asList(((DeleteIndexRequest) request).indices());
}
if (request instanceof BulkRequest) {
@SuppressWarnings("rawtypes") List<DocWriteRequest<?>> requests = ((BulkRequest) request).requests();
if (CollectionUtils.isNotEmpty(requests)) {
for (DocWriteRequest<?> docWriteRequest : requests) {
indexs.add(docWriteRequest.index());
}
return indexs;
}
}
if (request instanceof MultiGetRequest) {
List<Item> items = ((MultiGetRequest) request).getItems();
if (CollectionUtils.isNotEmpty(items)) {
for (Item item : items) {
indexs.add(item.index());
}
return indexs;
}
}
if (request instanceof GetMappingsRequest) {
return Arrays.asList(((GetMappingsRequest) request).indices());
}
if (request instanceof GetSettingsRequest) {
return Arrays.asList(((GetSettingsRequest) request).indices());
}
if (request instanceof IndicesExistsRequest) {
return Arrays.asList(((IndicesExistsRequest) request).indices());
}
if (request instanceof GetAliasesRequest) {
return Arrays.asList(((GetAliasesRequest) request).indices());
}
if (request instanceof GetIndexRequest) {
return Arrays.asList(((GetIndexRequest) request).indices());
}
if (request instanceof GetFieldMappingsRequest) {
return Arrays.asList(((GetFieldMappingsRequest) request).indices());
}
if (request instanceof TypesExistsRequest) {
return Arrays.asList(((TypesExistsRequest) request).indices());
}
if (request instanceof ValidateQueryRequest) {
return Arrays.asList(((ValidateQueryRequest) request).indices());
}
if (request instanceof RecoveryRequest) {
return Arrays.asList(((RecoveryRequest) request).indices());
}
if (request instanceof IndicesSegmentsRequest) {
return Arrays.asList(((IndicesSegmentsRequest) request).indices());
}
if (request instanceof IndicesShardStoresRequest) {
return Arrays.asList(((IndicesShardStoresRequest) request).indices());
}
if (request instanceof UpgradeStatusRequest) {
return Arrays.asList(((UpgradeStatusRequest) request).indices());
}
if (request instanceof ClusterSearchShardsRequest) {
return Arrays.asList(((ClusterSearchShardsRequest) request).indices());
}
if (request instanceof IndicesAliasesRequest) {
List<IndicesAliasesRequest.AliasActions> aliasActions = ((IndicesAliasesRequest) request).getAliasActions();
if (CollectionUtils.isNotEmpty(aliasActions)) {
for (IndicesAliasesRequest.AliasActions action : aliasActions) {
indexs.addAll(Arrays.asList(action.indices()));
}
return indexs;
}
}
if (request instanceof ClearIndicesCacheRequest) {
return Arrays.asList(((ClearIndicesCacheRequest) request).indices());
}
if (request instanceof CloseIndexRequest) {
return Arrays.asList(((CloseIndexRequest) request).indices());
}
if (request instanceof FlushRequest) {
return Arrays.asList(((FlushRequest) request).indices());
}
if (request instanceof SyncedFlushRequest) {
return Arrays.asList(((SyncedFlushRequest) request).indices());
}
if (request instanceof ForceMergeRequest) {
return Arrays.asList(((ForceMergeRequest) request).indices());
}
if (request instanceof RefreshRequest) {
return Arrays.asList(((RefreshRequest) request).indices());
}
if (request instanceof RolloverRequest) {
return Arrays.asList(((RolloverRequest) request).indices());
}
if (request instanceof UpdateSettingsRequest) {
return Arrays.asList(((UpdateSettingsRequest) request).indices());
}
if (request instanceof ResizeRequest) {
return Arrays.asList(((ResizeRequest) request).indices());
}
if (request instanceof DeleteIndexTemplateRequest) {
indexs.add(((DeleteIndexTemplateRequest) request).name());
return indexs;
}
if (request instanceof GetIndexTemplatesRequest) {
return Arrays.asList(((GetIndexTemplatesRequest) request).names());
}
if (request instanceof PutIndexTemplateRequest) {
indexs.add(((PutIndexTemplateRequest) request).name());
return indexs;
}
if (request instanceof UpgradeRequest) {
return Arrays.asList(((UpgradeRequest) request).indices());
}
if (request instanceof FieldCapabilitiesRequest) {
return Arrays.asList(((FieldCapabilitiesRequest) request).indices());
}
if (request instanceof MultiSearchRequest) {
List<SearchRequest> searchRequests = ((MultiSearchRequest) request).requests();
if (CollectionUtils.isNotEmpty(searchRequests)) {
for (SearchRequest singleRequest : searchRequests) {
indexs.addAll(Arrays.asList(singleRequest.indices()));
}
return indexs;
}
}
if (request instanceof MultiTermVectorsRequest) {
List<TermVectorsRequest> termVectorsRequests = ((MultiTermVectorsRequest) request).getRequests();
if (CollectionUtils.isNotEmpty(termVectorsRequests)) {
for (TermVectorsRequest singleRequest : termVectorsRequests) {
indexs.addAll(Arrays.asList(singleRequest.indices()));
}
return indexs;
}
}
if (request instanceof UpdateByQueryRequest) {
return Arrays.asList(((UpdateByQueryRequest) request).indices());
}
if (request instanceof DeleteByQueryRequest) {
return Arrays.asList(((DeleteByQueryRequest) request).indices());
}
if (request instanceof ReindexRequest) {
indexs.addAll(Arrays.asList(((ReindexRequest) request).getSearchRequest().indices()));
indexs.addAll(Arrays.asList(((ReindexRequest) request).getDestination().indices()));
return indexs;
}
// ClearScrollRequest does not carry any index, so return empty List
if (request instanceof ClearScrollRequest) {
return indexs;
}
// No matched request type to find specific index , set default value *
indexs.add("*");
return indexs;
}
Aggregations