Accessing gzipped response with RestClient or RestHighLevelClient

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

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.

Hi David,

Thank you for replying :slight_smile:

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

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.

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