controller.registerHandler(GET, "/{index}/_skywalker/reconstruct", this);
}
@Override
public void handleRequest(final RestRequest request, final RestChannel channel, final Client client) {
ReconstructIndexRequest r = new ReconstructIndexRequest(request.param("index"));
client.admin().indices().execute(ReconstructIndexAction.INSTANCE, r, new RestResponseListener<ReconstructIndexResponse>(channel) {
@Override
public RestResponse buildResponse(ReconstructIndexResponse response) throws Exception {
XContentBuilder builder = jsonBuilder();
builder.startObject()
.field("ok", true)
.field("index", request.param("index"))
.startArray("shards");
for (ShardReconstructIndexResponse r : response.shards()) {
XContentParser p = XContentHelper.createParser(r.getReconstructedIndex().bytes());
builder.copyCurrentStructure(p);
}
builder.endArray();
builder.endObject();
return new BytesRestResponse(OK, builder);