# Accessing gzipped response with RestClient or RestHighLevelClient

**URL:** <https://discuss.elastic.co/t/accessing-gzipped-response-with-restclient-or-resthighlevelclient/289538>\
**Category:** Elasticsearch\
**Tags:** language-clients\
**Created:** [November 18, 2021, 7:15am UTC](https://discuss.elastic.co/t/accessing-gzipped-response-with-restclient-or-resthighlevelclient/289538 "2021-11-18T07:15:37Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![soren.nohr](https://avatars.discourse-cdn.com/v4/letter/s/b77776/32.png) [@soren.nohr](https://discuss.elastic.co/u/soren.nohr)\
**Post date:** [November 18, 2021, 7:15am UTC](https://discuss.elastic.co/t/accessing-gzipped-response-with-restclient-or-resthighlevelclient/289538/1 "2021-11-18T07:15:37Z")

</div>

Hi All,

I am using the Java RestClient to do a search against an Elasticsearch cluster, requesting a gzipped response by setting the 'Accept-Encoding' header to 'gzip'. Using Wireshark I can see that the Elastic cluster returns gzipped content.

My question is - how can I access the still gzipped content from my Java code?

When doing;

`byte[] bytes = EntityUtils.toByteArray(response.getEntity());`

or

`byte[] bytes = response.getEntity().getContent().readAllBytes();`

`bytes` contains the decompressed response.

Thanks,

Søren

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [November 18, 2021, 8:38am UTC](https://discuss.elastic.co/t/accessing-gzipped-response-with-restclient-or-resthighlevelclient/289538/2 "2021-11-18T08:38:49Z")

</div>

Welcome!

Why would you need the compressed content? I'm curious.

I believe that the client knows how to deal with uncompressed or compressed content...  
And do whatever is needed to give back the requested POJO.

---

<div class="post-metadata">

**Author:** ![soren.nohr](https://avatars.discourse-cdn.com/v4/letter/s/b77776/32.png) [@soren.nohr](https://discuss.elastic.co/u/soren.nohr)\
**Post date:** [November 18, 2021, 8:42am UTC](https://discuss.elastic.co/t/accessing-gzipped-response-with-restclient-or-resthighlevelclient/289538/3 "2021-11-18T08:42:55Z")

</div>

Hi David,

Thank you for replying 🙂

I need the compressed response because I would like to forward it - still compressed - to another service that will then decompress and deserialize.

Søren

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [November 18, 2021, 9:01am UTC](https://discuss.elastic.co/t/accessing-gzipped-response-with-restclient-or-resthighlevelclient/289538/4 "2021-11-18T09:01:39Z")

</div>

I have no idea if this is possible and if the underlying lib can do that.

But, if it's doable, I guess you would need to use the LowLevel Client instead.

> **[Reading responses | Java REST Client \[7.15\] | Elastic](https://www.elastic.co/guide/en/elasticsearch/client/java-rest/current/java-rest-low-usage-responses.html)**

---

<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:** [December 16, 2021, 9:01am UTC](https://discuss.elastic.co/t/accessing-gzipped-response-with-restclient-or-resthighlevelclient/289538/5 "2021-12-16T09:01:54Z")

</div>

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