use of org.elasticsearch.action.admin.indices.shrink.ResizeResponse in project crate by crate.
the class AlterTableOperation method resizeIndex.
private CompletableFuture<Long> resizeIndex(IndexMetadata sourceIndex, @Nullable String sourceIndexAlias, String targetIndexName, int targetNumberOfShards) {
Settings targetIndexSettings = Settings.builder().put(SETTING_NUMBER_OF_SHARDS, targetNumberOfShards).build();
int currentNumShards = sourceIndex.getNumberOfShards();
ResizeRequest request = new ResizeRequest(targetIndexName, sourceIndex.getIndex().getName());
request.getTargetIndexRequest().settings(targetIndexSettings);
if (sourceIndexAlias != null) {
request.getTargetIndexRequest().alias(new Alias(sourceIndexAlias));
}
request.setResizeType(targetNumberOfShards > currentNumShards ? ResizeType.SPLIT : ResizeType.SHRINK);
request.setCopySettings(Boolean.TRUE);
request.setWaitForActiveShards(ActiveShardCount.ONE);
FutureActionListener<ResizeResponse, Long> listener = new FutureActionListener<>(resp -> resp.isAcknowledged() ? 1L : 0L);
transportResizeAction.execute(request, listener);
return listener;
}
Aggregations