Custom plugin for streaming results with RestHandler

Hello os community,

I’m trying to understand if it’s possible to create a RestHandler with a custom plugin that stream indices documents directly to the response handler as json/csv.

Unfortunately there is no documentation about this kind of behaviour and after multiple blind test I’m thinking it’s not possibile at all.

However the provided code show the existence of the method bytesOutput that return a BytesStreamOutput that maybe is usefull for the job.

public class ExportRestHandler extends BaseRestHandler {

    @Override
    protected RestChannelConsumer prepareRequest(RestRequest request, NodeClient client) throws IOException {
    	
        return channel -> {
        	
        	final BytesStreamOutput streamOutput = channel.bytesOutput();

			while(true) {
				streamOutput.write(...);
			}
        };
    }
}

But I can’t make it work.

Can somebody provide a simple example that can show how correctly implement the streaming feature (always if it’s tecnically possible by the framework).

Thanks in advance for the help

Checkout RestBulkStreamingAction

1 Like

Thank you @cwperks for the hint.
Looks like the method supportsStreaming was introduced in 2.15 but at the moment I’m locked at 2.12.

If there isn’t another solution, I will try in the near future after an upgrade to the latest version.

Thanks again