Can Elasticsearch stream the SearchResponse? Can Elasticsearch stream the SearchResponse? elasticsearch elasticsearch

Can Elasticsearch stream the SearchResponse?


A proposal for streaming results does exist but it doesn't seem to have picked up steam so far and was closed (for now).

There's a way to do it with XContentBuilder but that still requires the whole response to be in memory before being sent.

It might not be what you want, but that's the closest thing that I know which could fulfill your need. Worth giving it a try.


I believe there is no way to obtain an InputStream from the Java API (but I might be wrong). I also think there is no way to directly obtain an InputStream in Jest (a REST-based Elasticsearch Java API).

You mention that it is cumbersome to create the search request to the _search endpoint yourself: if you're referring to building the actual json query, I just would like to point out that once you have a SearchSourceBuilder, you can call toString() on it to get a fully working json representation of your query.

    SearchSourceBuilder sourceBuilder = new SearchSourceBuilder();    sourceBuilder.query(this.getQuery())            .from(this.getFrom())            .size(this.getSize())            .fetchSource(this.getSource(), null);    this.getSort().forEach(sourceBuilder::sort);    sourceBuilder.toString() // the json representation