# Java API for setting compression on \_source

**URL:** <https://discuss.elastic.co/t/java-api-for-setting-compression-on--source/8590>\
**Category:** Elasticsearch\
**Created:** [July 31, 2012, 10:11pm UTC](https://discuss.elastic.co/t/java-api-for-setting-compression-on--source/8590 "2012-07-31T22:11:02Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![re92](https://avatars.discourse-cdn.com/v4/letter/r/fbc32d/32.png) [@re92](https://discuss.elastic.co/u/re92)\
**Post date:** [July 31, 2012, 10:11pm UTC](https://discuss.elastic.co/t/java-api-for-setting-compression-on--source/8590/1 "2012-07-31T22:11:02Z")

</div>

I read the section here on compressing the source field:  
[http://www.elasticsearch.org/guide/reference/mapping/source-field.html](http://www.elasticsearch.org/guide/reference/mapping/source-field.html)

Is there a Java API that will allow me to set the "compress" value on the  
\_source field to true?

Thanks,  
Raj

---

<div class="post-metadata">

**Author:** ![mvg](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/mvg/32/98890_2.png) [@mvg](https://discuss.elastic.co/u/mvg)\
**Post date:** [August 1, 2012, 1:09pm UTC](https://discuss.elastic.co/t/java-api-for-setting-compression-on--source/8590/2 "2012-08-01T13:09:58Z")

</div>

Hi Raj,

There is no dedicated method for this in the api as far as I know. If  
you want to use the compress option from the Java api then it looks  
like this:  
String mapping =  
XContentFactory.jsonBuilder().startObject().startObject("type1")  
.startObject("\_source").field("compress", compress).endObject()  
.endObject().endObject().string();

client.admin().indices().preparePutMapping().setType("type1").setSource(mapping).execute().actionGet();

Martijn

On 1 August 2012 00:11, re92 [rajawesome@gmail.com](mailto:rajawesome@gmail.com) wrote:

> I read the section here on compressing the source field:  
> [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/reference/mapping/source-field.html)
> 
> Is there a Java API that will allow me to set the "compress" value on the  
> \_source field to true?
> 
> Thanks,  
> Raj

--  
Met vriendelijke groet,

Martijn van Groningen

---

<div class="post-metadata">

**Author:** ![re92](https://avatars.discourse-cdn.com/v4/letter/r/fbc32d/32.png) [@re92](https://discuss.elastic.co/u/re92)\
**Post date:** [August 1, 2012, 2:02pm UTC](https://discuss.elastic.co/t/java-api-for-setting-compression-on--source/8590/3 "2012-08-01T14:02:01Z")

</div>

Thanks Martin. I set it up with curl for now, but will follow your steps in  
Java.

Raj

On Wednesday, August 1, 2012 9:09:58 AM UTC-4, Martijn v Groningen wrote:

> Hi Raj,
> 
> There is no dedicated method for this in the api as far as I know. If  
> you want to use the compress option from the Java api then it looks  
> like this:  
> String mapping =  
> XContentFactory.jsonBuilder().startObject().startObject("type1")  
> .startObject("\_source").field("compress",  
> compress).endObject()  
> .endObject().endObject().string();
> 
> client.admin().indices().preparePutMapping().setType("type1").setSource(mapping).execute().actionGet();
> 
> Martijn
> 
> On 1 August 2012 00:11, re92 [rajawesome@gmail.com](mailto:rajawesome@gmail.com) wrote:
> 
> > I read the section here on compressing the source field:  
> > [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/reference/mapping/source-field.html)
> > 
> > Is there a Java API that will allow me to set the "compress" value on  
> > the  
> > \_source field to true?
> > 
> > Thanks,  
> > Raj
> 
> --  
> Met vriendelijke groet,
> 
> Martijn van Groningen

---

<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:** [July 6, 2017, 3:18am UTC](https://discuss.elastic.co/t/java-api-for-setting-compression-on--source/8590/4 "2017-07-06T03:18:09Z")

</div>


