# Converting bytes to SearchResponse

**URL:** <https://discuss.elastic.co/t/converting-bytes-to-searchresponse/120125>\
**Category:** Elasticsearch\
**Created:** [February 16, 2018, 8:51am UTC](https://discuss.elastic.co/t/converting-bytes-to-searchresponse/120125 "2018-02-16T08:51:55Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![ultimate.duwal](https://avatars.discourse-cdn.com/v4/letter/u/2acd7d/32.png) [@ultimate.duwal](https://discuss.elastic.co/u/ultimate.duwal)\
**Post date:** [February 16, 2018, 8:51am UTC](https://discuss.elastic.co/t/converting-bytes-to-searchresponse/120125/1 "2018-02-16T08:51:56Z")

</div>

I am working on a network streaming application and also works as a thin proxy server on top of elasticsearch. The application basically does is query on the ES cluster and then streams the response to a client application.

```
            XContentBuilder xContentBuilder = XContentFactory.jsonBuilder();
            xContentBuilder.startObject();
            response.toXContent(xContentBuilder, ToXContent.EMPTY_PARAMS);
            xContentBuilder.endObject();

```

bytes[] responseStreamBytes = xContentBuilder.bytes().toBytes();

The client side application should do is get the stream and convert the bytes array stream to SearchResponse again.  
How can this be done ?

i have done is use yse readFrom from SearchResponse class. However, it gives a error like

java.io.IOException: Can't read unknown type [121]  
at org.elasticsearch.common.io.stream.StreamInput.readGenericValue(StreamInput.java:433)  
at org.elasticsearch.common.io.stream.StreamInput.readMap(StreamInput.java:352)  
at org.elasticsearch.transport.TransportMessage.readFrom(TransportMessage.java:55)  
at org.elasticsearch.action.ActionResponse.readFrom(ActionResponse.java:35)  
at org.elasticsearch.action.search.SearchResponse.readFrom(SearchResponse.java:201)

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [March 16, 2018, 8:52am UTC](https://discuss.elastic.co/t/converting-bytes-to-searchresponse/120125/2 "2018-03-16T08:52:02Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
