# Http compression enabled but response not compressed

**URL:** <https://discuss.elastic.co/t/http-compression-enabled-but-response-not-compressed/103513>\
**Category:** Elasticsearch\
**Created:** [October 11, 2017, 8:59am UTC](https://discuss.elastic.co/t/http-compression-enabled-but-response-not-compressed/103513 "2017-10-11T08:59:17Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![Slade](https://avatars.discourse-cdn.com/v4/letter/s/b5ac83/32.png) [@Slade](https://discuss.elastic.co/u/Slade)\
**Post date:** [October 11, 2017, 8:59am UTC](https://discuss.elastic.co/t/http-compression-enabled-but-response-not-compressed/103513/1 "2017-10-11T08:59:17Z")

</div>

I set http.compression: true and http.compression\_level: 3 in the elasticsearch.yml file of each node in the cluster.  
Viewing the \_nodes/settings?pretty shows that it is indeed enabled.  
The problem is that the response from elastic is never actually compressed (Accept-Encoding header is being sent with gzip, deflate).  
Why are is the response never compressed? Am I missing a setting?

---

<div class="post-metadata">

**Author:** ![Slade](https://avatars.discourse-cdn.com/v4/letter/s/b5ac83/32.png) [@Slade](https://discuss.elastic.co/u/Slade)\
**Post date:** [October 11, 2017, 12:02pm UTC](https://discuss.elastic.co/t/http-compression-enabled-but-response-not-compressed/103513/2 "2017-10-11T12:02:38Z")

</div>

For clarification responses are compressed when I test locally on my Windows 10 machine with a single instance running. However on a two node cluster with the nodes running Ubuntu 1604 the responses never seem to be compressed. I've tested this with two different clusters, one cluster with nodes running 5.6.2 and one cluster with the nodes running 5.5.5 installed following [this guide](https://www.elastic.co/guide/en/elasticsearch/reference/current/deb.html).  
None of these clusters sent compressed responses. What could be the cause of this? How can this be troubleshooted?

---

<div class="post-metadata">

**Author:** ![Slade](https://avatars.discourse-cdn.com/v4/letter/s/b5ac83/32.png) [@Slade](https://discuss.elastic.co/u/Slade)\
**Post date:** [October 11, 2017, 1:28pm UTC](https://discuss.elastic.co/t/http-compression-enabled-but-response-not-compressed/103513/3 "2017-10-11T13:28:48Z")

</div>

I tried setting the network.host on my machine to my local ip rather than localhost and responses stopped being compressed. Why is this?

---

<div class="post-metadata">

**Author:** ![Slade](https://avatars.discourse-cdn.com/v4/letter/s/b5ac83/32.png) [@Slade](https://discuss.elastic.co/u/Slade)\
**Post date:** [October 12, 2017, 7:29am UTC](https://discuss.elastic.co/t/http-compression-enabled-but-response-not-compressed/103513/4 "2017-10-12T07:29:46Z")

</div>

It seems that elastic search will not compress responses if the host is anything other than localhost. Tested with 5.6.0. Not sure why this is.

---

<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:** [October 12, 2017, 7:31am UTC](https://discuss.elastic.co/t/http-compression-enabled-but-response-not-compressed/103513/5 "2017-10-12T07:31:37Z")

</div>

Could you tell how you discovered that (how do you know it's compressed or not)?

---

<div class="post-metadata">

**Author:** ![Slade](https://avatars.discourse-cdn.com/v4/letter/s/b5ac83/32.png) [@Slade](https://discuss.elastic.co/u/Slade)\
**Post date:** [October 12, 2017, 7:40am UTC](https://discuss.elastic.co/t/http-compression-enabled-but-response-not-compressed/103513/6 "2017-10-12T07:40:08Z")

</div>

The Content-Encoding header is sent as a response when calling /\_nodes/settings?pretty to the localhost host, whilst when performing the same request to my local ip it is not. Also the content-length is nearly three times smaller when performing the request to the localhost host,

---

<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:** [October 12, 2017, 7:51am UTC](https://discuss.elastic.co/t/http-compression-enabled-but-response-not-compressed/103513/7 "2017-10-12T07:51:19Z")

</div>

Great. Could you open an issue and write all those details including the `content-length` values that you have seen in both cases?

---

<div class="post-metadata">

**Author:** ![Slade](https://avatars.discourse-cdn.com/v4/letter/s/b5ac83/32.png) [@Slade](https://discuss.elastic.co/u/Slade)\
**Post date:** [October 12, 2017, 8:43am UTC](https://discuss.elastic.co/t/http-compression-enabled-but-response-not-compressed/103513/8 "2017-10-12T08:43:13Z")

</div>

[Done](https://github.com/elastic/elasticsearch/issues/26980)

---

<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:** [October 12, 2017, 12:03pm UTC](https://discuss.elastic.co/t/http-compression-enabled-but-response-not-compressed/103513/9 "2017-10-12T12:03:34Z")

</div>

Closing this thread. As you wrote on the issue you are actually using a 3rd party tool which does not ask for compression on remote hosts but only on localhost:

> It indeed compresses on hosts other than localhost when issuing the requests with curl, however when using postman or a web browser it does not. Not really sure what this could be caused by.

@tanguy ran a test which shows that everything is normal as soon as the client ask for it:

> Quick test I did on 5.6.2:
> 
> ```auto
> $ cat config/elasticsearch.yml | grep network
> network.host: ["localhost","127.0.0.1","192.168.1.15"]
> 
> ```
> 
> Now testing with curl with no `Accept-Encoding` header on `http://localhost:9200`,` http://127.0.0.1:9200`, `http://192.168.1.15:9200` and `http://laptop:9200` all return the same response headers:
> 
> ```auto
> curl -v -H 'Content-Type: application/json' -XGET 'http://localhost:9200/_nodes/settings?pretty&filter_path=cluster_name' 
> 
> * Connected to localhost (127.0.0.1) port 9200 (#0)
> > GET /_nodes/settings?pretty&filter_path=cluster_name HTTP/1.1
> > Host: localhost:9200
> > User-Agent: curl/7.52.1
> > Accept: */*
> > Content-Type: application/json
> 
> < HTTP/1.1 200 OK
> < content-type: application/json; charset=UTF-8
> < content-length: 39
> < 
> {
> "cluster_name" : "elasticsearch"
> }
> 
> ```
> 
> The test but with `Accept-Encoding: gzip` header returns:
> 
> ```auto
> curl -v -H 'Content-Type: application/json' -H 'Accept-Encoding: gzip' -XGET 'http://localhost:9200/_nodes/settings?pretty&filter_path=cluster_name'
> 
> * Connected to localhost (127.0.0.1) port 9200 (#0)
> > GET /_nodes/settings?pretty&filter_path=cluster_name HTTP/1.1
> > Host: localhost:9200
> > User-Agent: curl/7.52.1
> > Accept: */*
> > Content-Type: application/json
> > Accept-Encoding: gzip
> 
> < HTTP/1.1 200 OK
> < content-type: application/json; charset=UTF-8
> < content-encoding: gzip
> < content-length: 65
> < 
> ��RPPJ�)-.I-��K�MUR�RPJ�I,.�L.NM,J�P�������m,'%      
> 
> ```
> 
> I have the same result if I use ` http://127.0.0.1:9200`, `http://192.168.1.15:9200` and `http://laptop:9200` and I think this is the expected behaviour.

---

<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:** [November 9, 2017, 12:03pm UTC](https://discuss.elastic.co/t/http-compression-enabled-but-response-not-compressed/103513/10 "2017-11-09T12:03:52Z")

</div>

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