# How to compress data when write into es

**URL:** <https://discuss.elastic.co/t/how-to-compress-data-when-write-into-es/297371>\
**Category:** Elasticsearch\
**Created:** [February 16, 2022, 1:28pm UTC](https://discuss.elastic.co/t/how-to-compress-data-when-write-into-es/297371 "2022-02-16T13:28:58Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![dalei2019](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dalei2019/32/92374_2.png) [@dalei2019](https://discuss.elastic.co/u/dalei2019)\
**Post date:** [February 16, 2022, 1:28pm UTC](https://discuss.elastic.co/t/how-to-compress-data-when-write-into-es/297371/1 "2022-02-16T13:28:58Z")

</div>

Hi team,

I want to build an ES cluster for services in other regions, so ES needs to be exposed to the public network.

The amount of data transferred is 2 T /day , it's huge .  
So I expect to compress before writing into ES to save bandwidth transfer costs.

Is there any good way to achieve this or it has to be done through a new component?  
Any suggestions would be very helpful to me, thanks!

---

<div class="post-metadata">

**Author:** ![leandrojmp](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/leandrojmp/32/107231_2.png) [@leandrojmp](https://discuss.elastic.co/u/leandrojmp)\
**Post date:** [February 16, 2022, 1:59pm UTC](https://discuss.elastic.co/t/how-to-compress-data-when-write-into-es/297371/2 "2022-02-16T13:59:33Z")

</div>

It depends entirely on how are you planning to send the data as the compression should be done before sending the data to Elasticsearch.

If you are going to use Logstash or Filebeat then there is no issue, both tools support compression with the Elasticsearch output, it is not enabled per default but is pretty easy to configure.

If you are going to use other tool or a custom application, then you will need to check how to send a compressed http request to Elasticsearch on each case.

---

<div class="post-metadata">

**Author:** ![dalei2019](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dalei2019/32/92374_2.png) [@dalei2019](https://discuss.elastic.co/u/dalei2019)\
**Post date:** [February 17, 2022, 3:27am UTC](https://discuss.elastic.co/t/how-to-compress-data-when-write-into-es/297371/3 "2022-02-17T03:27:37Z")

</div>

Thanks @leandrojmp !

Follow your advice，I found this [http\_compression](https://www.elastic.co/guide/en/logstash/7.3/plugins-outputs-elasticsearch.html#plugins-outputs-elasticsearch-http_compression) parameter in logstash.

Does it mean that logstash can automatically send data to Elasticsearch in compressed format after it is turned on?

And Elasticsearch can automatically handle writing in compressed format?

---

<div class="post-metadata">

**Author:** ![leandrojmp](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/leandrojmp/32/107231_2.png) [@leandrojmp](https://discuss.elastic.co/u/leandrojmp)\
**Post date:** [February 17, 2022, 3:59am UTC](https://discuss.elastic.co/t/how-to-compress-data-when-write-into-es/297371/4 "2022-02-17T03:59:08Z")

</div>

Yes, if you set this option to `true`, logstash will send compressed data to Elasticsearch and Elasticsearch will decompress the data when it received the requests, no other change is needed.

---

<div class="post-metadata">

**Author:** ![dalei2019](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dalei2019/32/92374_2.png) [@dalei2019](https://discuss.elastic.co/u/dalei2019)\
**Post date:** [February 17, 2022, 7:42am UTC](https://discuss.elastic.co/t/how-to-compress-data-when-write-into-es/297371/5 "2022-02-17T07:42:20Z")

</div>

Thanks a lot , it's worked !

```auto
echo '{ "@timestamp": "2099-11-16T13:12:00", "message": "GET /search HTTP/1.1 200 1070000", "user": { "id": "hello" }}' \
|gzip \
|curl -v -i --data-binary @- -H "Content-Encoding: gzip" -H 'Content-Type: application/json' -u "elastic:password" 'http://1.2.3.4:9200/my-index-000001/_doc/?pretty'

```

---

<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 17, 2022, 7:43am UTC](https://discuss.elastic.co/t/how-to-compress-data-when-write-into-es/297371/6 "2022-03-17T07:43:17Z")

</div>

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