controller.registerHandler(GET, "/_segments", this);
controller.registerHandler(GET, "/{index}/_segments", this);
}
@Override public void handleRequest(final RestRequest request, final RestChannel channel) {
IndicesSegmentsRequest indicesSegmentsRequest = new IndicesSegmentsRequest(splitIndices(request.param("index")));
// we just send back a response, no need to fork a listener
indicesSegmentsRequest.listenerThreaded(false);
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;
}
indicesSegmentsRequest.operationThreading(operationThreading);
client.admin().indices().segments(indicesSegmentsRequest, new ActionListener<IndicesSegmentResponse>() {
@Override public void onResponse(IndicesSegmentResponse response) {
try {
XContentBuilder builder = RestXContentBuilder.restContentBuilder(request);
builder.startObject();