# Custom plugin for streaming results with RestHandler

**URL:** https://forum.opensearch.org/t/custom-plugin-for-streaming-results-with-resthandler/26668
**Category:** General Feedback
**Tags:** discuss
**Created:** [September 1, 2025, 12:35pm UTC](https://forum.opensearch.org/t/custom-plugin-for-streaming-results-with-resthandler/26668 "2025-09-01T12:35:37Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![jluca](https://avatars.discourse-cdn.com/v4/letter/j/94ad74/32.png) [@jluca](https://forum.opensearch.org/u/jluca)
#### Post date: [September 1, 2025, 12:35pm UTC](https://forum.opensearch.org/t/custom-plugin-for-streaming-results-with-resthandler/26668/1 "2025-09-01T12:35:38Z")

</div>

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.

```java
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

---

<div class="post-metadata">

### Author: ![cwperks](https://sea1.discourse-cdn.com/flex019/user_avatar/forum.opensearch.org/cwperks/32/4968_2.png) [@cwperks](https://forum.opensearch.org/u/cwperks)
#### Post date: [September 2, 2025, 1:19am UTC](https://forum.opensearch.org/t/custom-plugin-for-streaming-results-with-resthandler/26668/2 "2025-09-02T01:19:07Z")

</div>

Checkout [RestBulkStreamingAction](https://github.com/opensearch-project/OpenSearch/blob/main/server/src/main/java/org/opensearch/rest/action/document/RestBulkStreamingAction.java#L227-L230)

---

<div class="post-metadata">

### Author: ![jluca](https://avatars.discourse-cdn.com/v4/letter/j/94ad74/32.png) [@jluca](https://forum.opensearch.org/u/jluca)
#### Post date: [September 2, 2025, 3:52pm UTC](https://forum.opensearch.org/t/custom-plugin-for-streaming-results-with-resthandler/26668/3 "2025-09-02T15:52:52Z")

</div>

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
