IndexService indexService = indicesService.indexServiceSafe(request.index());
IndexShard indexShard = indexService.shardSafe(request.shardId());
SearchShardTarget shardTarget = new SearchShardTarget(clusterService.localNode().id(), request.index(), request.shardId());
ExportContext context = new ExportContext(0,
new ShardSearchRequest().types(request.types()).filteringAliases(request.filteringAliases()),
shardTarget, indexShard.searcher(), indexService, indexShard, scriptService, cacheRecycler, nodePath);
ExportContext.setCurrent(context);
try {
BytesReference source = request.source();
exportParser.parseSource(context, source);
context.preProcess();
exporter.check(context);
try {
if (context.explain()) {
return new ShardExportResponse(shardTarget.nodeIdText(), request.index(), request.shardId(), context.outputCmd(), context.outputCmdArray(), context.outputFile());
} else {
Exporter.Result res = exporter.execute(context);
return new ShardExportResponse(shardTarget.nodeIdText(), request.index(), request.shardId(), context.outputCmd(), context.outputCmdArray(), context.outputFile(), res.outputResult.stdErr, res.outputResult.stdOut, res.outputResult.exit, res.numExported);
}
} catch (Exception e) {
throw new QueryPhaseExecutionException(context, "failed to execute export", e);
}