Search in sources :

Example 1 with ShrinkRequest

use of org.elasticsearch.action.admin.indices.shrink.ShrinkRequest in project elasticsearch by elastic.

the class RestShrinkIndexAction method prepareRequest.

@Override
public RestChannelConsumer prepareRequest(final RestRequest request, final NodeClient client) throws IOException {
    if (request.param("target") == null) {
        throw new IllegalArgumentException("no target index");
    }
    if (request.param("index") == null) {
        throw new IllegalArgumentException("no source index");
    }
    ShrinkRequest shrinkIndexRequest = new ShrinkRequest(request.param("target"), request.param("index"));
    request.applyContentParser(parser -> ShrinkRequest.PARSER.parse(parser, shrinkIndexRequest, null));
    shrinkIndexRequest.timeout(request.paramAsTime("timeout", shrinkIndexRequest.timeout()));
    shrinkIndexRequest.masterNodeTimeout(request.paramAsTime("master_timeout", shrinkIndexRequest.masterNodeTimeout()));
    shrinkIndexRequest.setWaitForActiveShards(ActiveShardCount.parseString(request.param("wait_for_active_shards")));
    return channel -> client.admin().indices().shrinkIndex(shrinkIndexRequest, new AcknowledgedRestListener<ShrinkResponse>(channel) {

        @Override
        public void addCustomFields(XContentBuilder builder, ShrinkResponse response) throws IOException {
            response.addCustomFields(builder);
        }
    });
}
Also used : ActiveShardCount(org.elasticsearch.action.support.ActiveShardCount) BaseRestHandler(org.elasticsearch.rest.BaseRestHandler) Settings(org.elasticsearch.common.settings.Settings) ShrinkRequest(org.elasticsearch.action.admin.indices.shrink.ShrinkRequest) ShrinkResponse(org.elasticsearch.action.admin.indices.shrink.ShrinkResponse) RestRequest(org.elasticsearch.rest.RestRequest) NodeClient(org.elasticsearch.client.node.NodeClient) IOException(java.io.IOException) XContentBuilder(org.elasticsearch.common.xcontent.XContentBuilder) RestController(org.elasticsearch.rest.RestController) AcknowledgedRestListener(org.elasticsearch.rest.action.AcknowledgedRestListener) IOException(java.io.IOException) ShrinkRequest(org.elasticsearch.action.admin.indices.shrink.ShrinkRequest) ShrinkResponse(org.elasticsearch.action.admin.indices.shrink.ShrinkResponse) XContentBuilder(org.elasticsearch.common.xcontent.XContentBuilder)

Aggregations

IOException (java.io.IOException)1 ShrinkRequest (org.elasticsearch.action.admin.indices.shrink.ShrinkRequest)1 ShrinkResponse (org.elasticsearch.action.admin.indices.shrink.ShrinkResponse)1 ActiveShardCount (org.elasticsearch.action.support.ActiveShardCount)1 NodeClient (org.elasticsearch.client.node.NodeClient)1 Settings (org.elasticsearch.common.settings.Settings)1 XContentBuilder (org.elasticsearch.common.xcontent.XContentBuilder)1 BaseRestHandler (org.elasticsearch.rest.BaseRestHandler)1 RestController (org.elasticsearch.rest.RestController)1 RestRequest (org.elasticsearch.rest.RestRequest)1 AcknowledgedRestListener (org.elasticsearch.rest.action.AcknowledgedRestListener)1