protected Action<ExportRequest, ExportResponse, ExportRequestBuilder> action() {
return ExportAction.INSTANCE;
}
public void handleRequest(final RestRequest request, final RestChannel channel) {
ExportRequest exportRequest = new ExportRequest(RestActions.splitIndices(request.param("index")));
if (request.hasParam("ignore_indices")) {
exportRequest.ignoreIndices(IgnoreIndices.fromString(request.param("ignore_indices")));
}
exportRequest.listenerThreaded(false);
try {
BroadcastOperationThreading operationThreading = BroadcastOperationThreading.fromString(request.param("operation_threading"), BroadcastOperationThreading.SINGLE_THREAD);
if (operationThreading == BroadcastOperationThreading.NO_THREADS) {
// since we don't spawn, don't allow no_threads, but change it to a single thread
operationThreading = BroadcastOperationThreading.SINGLE_THREAD;
}
exportRequest.operationThreading(operationThreading);
if (request.hasContent()) {
exportRequest.source(request.content(), request.contentUnsafe());
} else {
String source = request.param("source");
if (source != null) {
exportRequest.source(source);
} else {
BytesReference querySource = RestActions.parseQuerySource(request);
if (querySource != null) {
exportRequest.source(querySource, false);
}
}
}
exportRequest.routing(request.param("routing"));
exportRequest.types(splitTypes(request.param("type")));
exportRequest.preference(request.param("preference", "_primary"));
} catch (Exception e) {
try {
XContentBuilder builder = RestXContentBuilder.restContentBuilder(request);
channel.sendResponse(new XContentRestResponse(request, BAD_REQUEST, builder.startObject().field("error", e.getMessage()).endObject()));
} catch (IOException e1) {