# Mapping and Dynamic Mapping

**URL:** https://discuss.elastic.co/t/mapping-and-dynamic-mapping/4554
**Category:** Elasticsearch
**Created:** [June 4, 2011, 2:55pm UTC](https://discuss.elastic.co/t/mapping-and-dynamic-mapping/4554 "2011-06-04T14:55:34Z")
**Posts on this page:** 15
**Page:** 1

<div class="post-metadata">

### Author: ![Slava\_G](https://avatars.discourse-cdn.com/v4/letter/s/e9c0ed/32.png) [@Slava\_G](https://discuss.elastic.co/u/Slava_G)
#### Post date: [June 4, 2011, 2:55pm UTC](https://discuss.elastic.co/t/mapping-and-dynamic-mapping/4554/1 "2011-06-04T14:55:34Z")

</div>

Hi,  
I'm trying to disable \_source field, using this:  
XContentBuilder data = jsonBuilder().startObject()  
.startObject("type")  
.startObject("\_source")  
.field("enabled", false)  
.endObject()  
.endObject()  
.endObject();

client.admin().indices().create(new  
CreateIndexRequest("index").mapping("type", data ));  
And looks like \_source is indeed not stored.

Then I'm doing index with:

XContentBuilder jsonBuilder = XContentFactory.jsonBuilder();  
jsonBuilder.startObject();  
jsonBuilder.field(FROMFIELD,addr.toString());  
jsonBuilder.field(RECIPIENTFIELD,addr.toString());  
jsonBuilder.field(SUBJECTFIELD,message.getSubject());  
jsonBuilder.field("bckdate",backuptimstamp);  
jsonBuilder.endObject();

IndexRequestBuilder indexRequest =  
client.prepareIndex(this.tenant,this.type,id).setSource(jsonBuilder);  
IndexResponse response = indexRequest.execute().actionGet();

The search result returns hits, without source field but as well  
without any other field , even on search I'm adding those fields.

Looks like schema is not updated, the question after such a manual  
mapping, should schema be updated on index with new fields ?

Thank You and Best Regards.

---

<div class="post-metadata">

### Author: ![kimchy](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/kimchy/32/44952_2.png) [@kimchy](https://discuss.elastic.co/u/kimchy)
#### Post date: [June 4, 2011, 4:47pm UTC](https://discuss.elastic.co/t/mapping-and-dynamic-mapping/4554/2 "2011-06-04T16:47:16Z")

</div>

If you don't store the source, then you need to explicitly store specific fields (and ask for them in the search request) if you want them. It usually makes sense to use the \_source field then storing specific fields separately.

On Saturday, June 4, 2011 at 5:55 PM, slavag wrote:

> Hi,  
> I'm trying to disable \_source field, using this:  
> XContentBuilder data = jsonBuilder().startObject()  
> .startObject("type")  
> .startObject("\_source")  
> .field("enabled", false)  
> .endObject()  
> .endObject()  
> .endObject();
> 
> client.admin().indices().ccreate(new  
> CreateIndexRequest("index").mapping("type", data ));  
> And looks like \_source is indeed not stored.
> 
> Then I'm doing index with:
> 
> XContentBuilder jsonBuilder = XContentFactory.jsonBuilder();  
> jsonBuilder.startObject();  
> jsonBuilder.field(FROMFIELD,addr.toString());  
> jsonBuilder.field(RECIPIENTFIELD,addr.toString());  
> jsonBuilder.field(SUBJECTFIELD,message.getSubject());  
> jsonBuilder.field("bckdate",backuptimstamp);  
> jsonBuilder.endObject();
> 
> IndexRequestBuilder indexRequest =  
> client.prepareIndex(this.tenant,this.type,id).setSource(jsonBuilder);  
> IndexResponse response = indexRequest.execute().actionGet();
> 
> The search result returns hits, without source field but as well  
> without any other field , even on search I'm adding those fields.
> 
> Looks like schema is not updated, the question after such a manual  
> mapping, should schema be updated on index with new fields ?
> 
> Thank You and Best Regards.

---

<div class="post-metadata">

### Author: ![Slava\_G](https://avatars.discourse-cdn.com/v4/letter/s/e9c0ed/32.png) [@Slava\_G](https://discuss.elastic.co/u/Slava_G)
#### Post date: [June 4, 2011, 6:09pm UTC](https://discuss.elastic.co/t/mapping-and-dynamic-mapping/4554/3 "2011-06-04T18:09:47Z")

</div>

Hi Shay, thank for a quick response,  
What do you mean when saying to explicitly store specific fields , I'm  
putting them into to JsonBuilder (in the search I do ask for them) ?

Best Regards.

On Jun 4, 7:47 pm, Shay Banon [shay.ba...@elasticsearch.com](mailto:shay.ba...@elasticsearch.com) wrote:

> If you don't store the source, then you need to explicitly store specific fields (and ask for them in the search request) if you want them. It usually makes sense to use the \_source field then storing specific fields separately.
> 
> On Saturday, June 4, 2011 at 5:55 PM, slavag wrote:
> 
> > Hi,  
> > I'm trying to disable \_source field, using this:  
> > XContentBuilder data = jsonBuilder().startObject()  
> > .startObject("type")  
> > .startObject("\_source")  
> > .field("enabled", false)  
> > .endObject()  
> > .endObject()  
> > .endObject();
> 
> > client.admin().indices().ccreate(new  
> > CreateIndexRequest("index").mapping("type", data ));  
> > And looks like \_source is indeed not stored.
> 
> > Then I'm doing index with:
> 
> > XContentBuilder jsonBuilder = XContentFactory.jsonBuilder();  
> > jsonBuilder.startObject();  
> > jsonBuilder.field(FROMFIELD,addr.toString());  
> > jsonBuilder.field(RECIPIENTFIELD,addr.toString());  
> > jsonBuilder.field(SUBJECTFIELD,message.getSubject());  
> > jsonBuilder.field("bckdate",backuptimstamp);  
> > jsonBuilder.endObject();
> 
> > IndexRequestBuilder indexRequest =  
> > client.prepareIndex(this.tenant,this.type,id).setSource(jsonBuilder);  
> > IndexResponse response = indexRequest.execute().actionGet();
> 
> > The search result returns hits, without source field but as well  
> > without any other field , even on search I'm adding those fields.
> 
> > Looks like schema is not updated, the question after such a manual  
> > mapping, should schema be updated on index with new fields ?
> 
> > Thank You and Best Regards.

---

<div class="post-metadata">

### Author: ![kimchy](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/kimchy/32/44952_2.png) [@kimchy](https://discuss.elastic.co/u/kimchy)
#### Post date: [June 4, 2011, 6:14pm UTC](https://discuss.elastic.co/t/mapping-and-dynamic-mapping/4554/4 "2011-06-04T18:14:56Z")

</div>

You need to set store to yes in hte mapping for the relevant fields you want to retrieve. Check the mappings section in the guide.

On Saturday, June 4, 2011 at 9:09 PM, slavag wrote:

> Hi Shay, thank for a quick response,  
> What do you mean when saying to explicitly store specific fields , I'm  
> putting them into to JsonBuilder (in the search I do ask for them) ?
> 
> Best Regards.
> 
> On Jun 4, 7:47 pm, Shay Banon \<[shay.ba...@elasticsearch.com](mailto:shay.ba...@elasticsearch.com) ([http://elasticsearch.com](http://elasticsearch.com))\> wrote:
> 
> > If you don't store the source, then you need to explicitly store specific fields (and ask for them in the search request) if you want them. It usually makes sense to use the \_source field then storing specific fields separately.
> > 
> > On Saturday, June 4, 2011 at 5:55 PM, slavag wrote:
> > 
> > > Hi,  
> > > I'm trying to disable \_source field, using this:  
> > > XContentBuilder data = jsonBuilder().startObject()  
> > > .startObject("type")  
> > > .startObject("\_source")  
> > > .field("enabled", false)  
> > > .endObject()  
> > > .endObject()  
> > > .endObject();
> > 
> > > client.admin().indices().ccreate(new  
> > > CreateIndexRequest("index").mapping("type", data ));  
> > > And looks like \_source is indeed not stored.
> > 
> > > Then I'm doing index with:
> > 
> > > XContentBuilder jsonBuilder = XContentFactory.jsonBuilder();  
> > > jsonBuilder.startObject();  
> > > jsonBuilder.field(FROMFIELD,addr.toString());  
> > > jsonBuilder.field(RECIPIENTFIELD,addr.toString());  
> > > jsonBuilder.field(SUBJECTFIELD,message.getSubject());  
> > > jsonBuilder.field("bckdate",backuptimstamp);  
> > > jsonBuilder.endObject();
> > 
> > > IndexRequestBuilder indexRequest =  
> > > client.prepareIndex(this.tenant,this.type,id).setSource(jsonBuilder);  
> > > IndexResponse response = indexRequest.execute().actionGet();
> > 
> > > The search result returns hits, without source field but as well  
> > > without any other field , even on search I'm adding those fields.
> > 
> > > Looks like schema is not updated, the question after such a manual  
> > > mapping, should schema be updated on index with new fields ?
> > 
> > > Thank You and Best Regards.

---

<div class="post-metadata">

### Author: ![Slava\_G](https://avatars.discourse-cdn.com/v4/letter/s/e9c0ed/32.png) [@Slava\_G](https://discuss.elastic.co/u/Slava_G)
#### Post date: [June 4, 2011, 6:19pm UTC](https://discuss.elastic.co/t/mapping-and-dynamic-mapping/4554/5 "2011-06-04T18:19:39Z")

</div>

That what I'm trying to understand, I read this section and still  
confused, when I'm using such mapping (not dynamic) and then new  
fields are cumming - it means I need explicitly to create a mapping  
for them ? Or there other way to make mapping dynamic after once I  
used static mapping (for \_source).

Best Regards.

On Jun 4, 9:14 pm, Shay Banon [shay.ba...@elasticsearch.com](mailto:shay.ba...@elasticsearch.com) wrote:

> You need to set store to yes in hte mapping for the relevant fields you want to retrieve. Check the mappings section in the guide.
> 
> On Saturday, June 4, 2011 at 9:09 PM, slavag wrote:
> 
> > Hi Shay, thank for a quick response,  
> > What do you mean when saying to explicitly store specific fields , I'm  
> > putting them into to JsonBuilder (in the search I do ask for them) ?
> 
> > Best Regards.
> 
> > On Jun 4, 7:47 pm, Shay Banon \<[shay.ba...@elasticsearch.com](mailto:shay.ba...@elasticsearch.com) ([http://elasticsearch.com](http://elasticsearch.com))\> wrote:
> > 
> > > If you don't store the source, then you need to explicitly store specific fields (and ask for them in the search request) if you want them. It usually makes sense to use the \_source field then storing specific fields separately.
> 
> > > On Saturday, June 4, 2011 at 5:55 PM, slavag wrote:
> > > 
> > > > Hi,  
> > > > I'm trying to disable \_source field, using this:  
> > > > XContentBuilder data = jsonBuilder().startObject()  
> > > > .startObject("type")  
> > > > .startObject("\_source")  
> > > > .field("enabled", false)  
> > > > .endObject()  
> > > > .endObject()  
> > > > .endObject();
> 
> > > > client.admin().indices().ccreate(new  
> > > > CreateIndexRequest("index").mapping("type", data ));  
> > > > And looks like \_source is indeed not stored.
> 
> > > > Then I'm doing index with:
> 
> > > > XContentBuilder jsonBuilder = XContentFactory.jsonBuilder();  
> > > > jsonBuilder.startObject();  
> > > > jsonBuilder.field(FROMFIELD,addr.toString());  
> > > > jsonBuilder.field(RECIPIENTFIELD,addr.toString());  
> > > > jsonBuilder.field(SUBJECTFIELD,message.getSubject());  
> > > > jsonBuilder.field("bckdate",backuptimstamp);  
> > > > jsonBuilder.endObject();
> 
> > > > IndexRequestBuilder indexRequest =  
> > > > client.prepareIndex(this.tenant,this.type,id).setSource(jsonBuilder);  
> > > > IndexResponse response = indexRequest.execute().actionGet();
> 
> > > > The search result returns hits, without source field but as well  
> > > > without any other field , even on search I'm adding those fields.
> 
> > > > Looks like schema is not updated, the question after such a manual  
> > > > mapping, should schema be updated on index with new fields ?
> 
> > > > Thank You and Best Regards.

---

<div class="post-metadata">

### Author: ![kimchy](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/kimchy/32/44952_2.png) [@kimchy](https://discuss.elastic.co/u/kimchy)
#### Post date: [June 4, 2011, 6:21pm UTC](https://discuss.elastic.co/t/mapping-and-dynamic-mapping/4554/6 "2011-06-04T18:21:10Z")

</div>

You can use dynamic templates to try and define which fields will be stored based on some matching scheme: [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/reference/mapping/root-object-type.html).

On Saturday, June 4, 2011 at 9:19 PM, slavag wrote:

> That what I'm trying to understand, I read this section and still  
> confused, when I'm using such mapping (not dynamic) and then new  
> fields are cumming - it means I need explicitly to create a mapping  
> for them ? Or there other way to make mapping dynamic after once I  
> used static mapping (for \_source).
> 
> Best Regards.
> 
> On Jun 4, 9:14 pm, Shay Banon \<[shay.ba...@elasticsearch.com](mailto:shay.ba...@elasticsearch.com) ([http://elasticsearch.com](http://elasticsearch.com))\> wrote:
> 
> > You need to set store to yes in hte mapping for the relevant fields you want to retrieve. Check the mappings section in the guide.
> > 
> > On Saturday, June 4, 2011 at 9:09 PM, slavag wrote:
> > 
> > > Hi Shay, thank for a quick response,  
> > > What do you mean when saying to explicitly store specific fields , I'm  
> > > putting them into to JsonBuilder (in the search I do ask for them) ?
> > 
> > > Best Regards.
> > 
> > > On Jun 4, 7:47 pm, Shay Banon \<[shay.ba...@elasticsearch.com](mailto:shay.ba...@elasticsearch.com) ([http://elasticsearch.com](http://elasticsearch.com)) ([http://elasticsearch.com](http://elasticsearch.com))\> wrote:
> > > 
> > > > If you don't store the source, then you need to explicitly store specific fields (and ask for them in the search request) if you want them. It usually makes sense to use the \_source field then storing specific fields separately.
> > 
> > > > On Saturday, June 4, 2011 at 5:55 PM, slavag wrote:
> > > > 
> > > > > Hi,  
> > > > > I'm trying to disable \_source field, using this:  
> > > > > XContentBuilder data = jsonBuilder().startObject()  
> > > > > .startObject("type")  
> > > > > .startObject("\_source")  
> > > > > .field("enabled", false)  
> > > > > .endObject()  
> > > > > .endObject()  
> > > > > .endObject();
> > 
> > > > > client.admin().indices().ccreate(new  
> > > > > CreateIndexRequest("index").mapping("type", data ));  
> > > > > And looks like \_source is indeed not stored.
> > 
> > > > > Then I'm doing index with:
> > 
> > > > > XContentBuilder jsonBuilder = XContentFactory.jsonBuilder();  
> > > > > jsonBuilder.startObject();  
> > > > > jsonBuilder.field(FROMFIELD,addr.toString());  
> > > > > jsonBuilder.field(RECIPIENTFIELD,addr.toString());  
> > > > > jsonBuilder.field(SUBJECTFIELD,message.getSubject());  
> > > > > jsonBuilder.field("bckdate",backuptimstamp);  
> > > > > jsonBuilder.endObject();
> > 
> > > > > IndexRequestBuilder indexRequest =  
> > > > > client.prepareIndex(this.tenant,this.type,id).setSource(jsonBuilder);  
> > > > > IndexResponse response = indexRequest.execute().actionGet();
> > 
> > > > > The search result returns hits, without source field but as well  
> > > > > without any other field , even on search I'm adding those fields.
> > 
> > > > > Looks like schema is not updated, the question after such a manual  
> > > > > mapping, should schema be updated on index with new fields ?
> > 
> > > > > Thank You and Best Regards.

---

<div class="post-metadata">

### Author: ![Slava\_G](https://avatars.discourse-cdn.com/v4/letter/s/e9c0ed/32.png) [@Slava\_G](https://discuss.elastic.co/u/Slava_G)
#### Post date: [June 4, 2011, 6:25pm UTC](https://discuss.elastic.co/t/mapping-and-dynamic-mapping/4554/7 "2011-06-04T18:25:20Z")

</div>

Btw, when I used default-mapping.json and put there:  
{  
"TEST" : {  
"\_source" : {"enabled" : false}  
}  
}

It worked and all fields are stored by default, should it work in this  
way ?

P.S. Still have  
On Jun 4, 9:21 pm, Shay Banon [shay.ba...@elasticsearch.com](mailto:shay.ba...@elasticsearch.com) wrote:

> You can use dynamic templates to try and define which fields will be stored based on some matching scheme:[Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/reference/mapping/root-object-type)....
> 
> On Saturday, June 4, 2011 at 9:19 PM, slavag wrote:
> 
> > That what I'm trying to understand, I read this section and still  
> > confused, when I'm using such mapping (not dynamic) and then new  
> > fields are cumming - it means I need explicitly to create a mapping  
> > for them ? Or there other way to make mapping dynamic after once I  
> > used static mapping (for \_source).
> 
> > Best Regards.
> 
> > On Jun 4, 9:14 pm, Shay Banon \<[shay.ba...@elasticsearch.com](mailto:shay.ba...@elasticsearch.com) ([http://elasticsearch.com](http://elasticsearch.com))\> wrote:
> > 
> > > You need to set store to yes in hte mapping for the relevant fields you want to retrieve. Check the mappings section in the guide.
> 
> > > On Saturday, June 4, 2011 at 9:09 PM, slavag wrote:
> > > 
> > > > Hi Shay, thank for a quick response,  
> > > > What do you mean when saying to explicitly store specific fields , I'm  
> > > > putting them into to JsonBuilder (in the search I do ask for them) ?
> 
> > > > Best Regards.
> 
> > > > On Jun 4, 7:47 pm, Shay Banon \<[shay.ba...@elasticsearch.com](mailto:shay.ba...@elasticsearch.com) ([http://elasticsearch.com](http://elasticsearch.com)) ([http://elasticsearch.com](http://elasticsearch.com))\> wrote:
> > > > 
> > > > > If you don't store the source, then you need to explicitly store specific fields (and ask for them in the search request) if you want them. It usually makes sense to use the \_source field then storing specific fields separately.
> 
> > > > > On Saturday, June 4, 2011 at 5:55 PM, slavag wrote:
> > > > > 
> > > > > > Hi,  
> > > > > > I'm trying to disable \_source field, using this:  
> > > > > > XContentBuilder data = jsonBuilder().startObject()  
> > > > > > .startObject("type")  
> > > > > > .startObject("\_source")  
> > > > > > .field("enabled", false)  
> > > > > > .endObject()  
> > > > > > .endObject()  
> > > > > > .endObject();
> 
> > > > > > client.admin().indices().ccreate(new  
> > > > > > CreateIndexRequest("index").mapping("type", data ));  
> > > > > > And looks like \_source is indeed not stored.
> 
> > > > > > Then I'm doing index with:
> 
> > > > > > XContentBuilder jsonBuilder = XContentFactory.jsonBuilder();  
> > > > > > jsonBuilder.startObject();  
> > > > > > jsonBuilder.field(FROMFIELD,addr.toString());  
> > > > > > jsonBuilder.field(RECIPIENTFIELD,addr.toString());  
> > > > > > jsonBuilder.field(SUBJECTFIELD,message.getSubject());  
> > > > > > jsonBuilder.field("bckdate",backuptimstamp);  
> > > > > > jsonBuilder.endObject();
> 
> > > > > > IndexRequestBuilder indexRequest =  
> > > > > > client.prepareIndex(this.tenant,this.type,id).setSource(jsonBuilder);  
> > > > > > IndexResponse response = indexRequest.execute().actionGet();
> 
> > > > > > The search result returns hits, without source field but as well  
> > > > > > without any other field , even on search I'm adding those fields.
> 
> > > > > > Looks like schema is not updated, the question after such a manual  
> > > > > > mapping, should schema be updated on index with new fields ?
> 
> > > > > > Thank You and Best Regards.

---

<div class="post-metadata">

### Author: ![kimchy](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/kimchy/32/44952_2.png) [@kimchy](https://discuss.elastic.co/u/kimchy)
#### Post date: [June 4, 2011, 6:26pm UTC](https://discuss.elastic.co/t/mapping-and-dynamic-mapping/4554/8 "2011-06-04T18:26:03Z")

</div>

No it won't, all fields will not be stored by default.

On Saturday, June 4, 2011 at 9:25 PM, slavag wrote:

> Btw, when I used default-mapping.json and put there:  
> {  
> "TEST" : {  
> "\_source" : {"enabled" : false}  
> }  
> }
> 
> It worked and all fields are stored by default, should it work in this  
> way ?
> 
> P.S. Still have  
> On Jun 4, 9:21 pm, Shay Banon \<[shay.ba...@elasticsearch.com](mailto:shay.ba...@elasticsearch.com) ([http://elasticsearch.com](http://elasticsearch.com))\> wrote:
> 
> > You can use dynamic templates to try and define which fields will be stored based on some matching scheme:[Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/reference/mapping/root-object-type)....
> > 
> > On Saturday, June 4, 2011 at 9:19 PM, slavag wrote:
> > 
> > > That what I'm trying to understand, I read this section and still  
> > > confused, when I'm using such mapping (not dynamic) and then new  
> > > fields are cumming - it means I need explicitly to create a mapping  
> > > for them ? Or there other way to make mapping dynamic after once I  
> > > used static mapping (for \_source).
> > 
> > > Best Regards.
> > 
> > > On Jun 4, 9:14 pm, Shay Banon \<[shay.ba...@elasticsearch.com](mailto:shay.ba...@elasticsearch.com) ([http://elasticsearch.com](http://elasticsearch.com))\> wrote:
> > > 
> > > > You need to set store to yes in hte mapping for the relevant fields you want to retrieve. Check the mappings section in the guide.
> > 
> > > > On Saturday, June 4, 2011 at 9:09 PM, slavag wrote:
> > > > 
> > > > > Hi Shay, thank for a quick response,  
> > > > > What do you mean when saying to explicitly store specific fields , I'm  
> > > > > putting them into to JsonBuilder (in the search I do ask for them) ?
> > 
> > > > > Best Regards.
> > 
> > > > > On Jun 4, 7:47 pm, Shay Banon \<[shay.ba...@elasticsearch.com](mailto:shay.ba...@elasticsearch.com) ([http://elasticsearch.com](http://elasticsearch.com)) ([http://elasticsearch.com](http://elasticsearch.com))\> wrote:
> > > > > 
> > > > > > If you don't store the source, then you need to explicitly store specific fields (and ask for them in the search request) if you want them. It usually makes sense to use the \_source field then storing specific fields separately.
> > 
> > > > > > On Saturday, June 4, 2011 at 5:55 PM, slavag wrote:
> > > > > > 
> > > > > > > Hi,  
> > > > > > > I'm trying to disable \_source field, using this:  
> > > > > > > XContentBuilder data = jsonBuilder().startObject()  
> > > > > > > .startObject("type")  
> > > > > > > .startObject("\_source")  
> > > > > > > .field("enabled", false)  
> > > > > > > .endObject()  
> > > > > > > .endObject()  
> > > > > > > .endObject();
> > 
> > > > > > > client.admin().indices().ccreate(new  
> > > > > > > CreateIndexRequest("index").mapping("type", data ));  
> > > > > > > And looks like \_source is indeed not stored.
> > 
> > > > > > > Then I'm doing index with:
> > 
> > > > > > > XContentBuilder jsonBuilder = XContentFactory.jsonBuilder();  
> > > > > > > jsonBuilder.startObject();  
> > > > > > > jsonBuilder.field(FROMFIELD,addr.toString());  
> > > > > > > jsonBuilder.field(RECIPIENTFIELD,addr.toString());  
> > > > > > > jsonBuilder.field(SUBJECTFIELD,message.getSubject());  
> > > > > > > jsonBuilder.field("bckdate",backuptimstamp);  
> > > > > > > jsonBuilder.endObject();
> > 
> > > > > > > IndexRequestBuilder indexRequest =  
> > > > > > > client.prepareIndex(this.tenant,this.type,id).setSource(jsonBuilder);  
> > > > > > > IndexResponse response = indexRequest.execute().actionGet();
> > 
> > > > > > > The search result returns hits, without source field but as well  
> > > > > > > without any other field , even on search I'm adding those fields.
> > 
> > > > > > > Looks like schema is not updated, the question after such a manual  
> > > > > > > mapping, should schema be updated on index with new fields ?
> > 
> > > > > > > Thank You and Best Regards.

---

<div class="post-metadata">

### Author: ![Slava\_G](https://avatars.discourse-cdn.com/v4/letter/s/e9c0ed/32.png) [@Slava\_G](https://discuss.elastic.co/u/Slava_G)
#### Post date: [June 4, 2011, 6:27pm UTC](https://discuss.elastic.co/t/mapping-and-dynamic-mapping/4554/9 "2011-06-04T18:27:45Z")

</div>

Strange, as I did this on clean elasticsearch and it work as I  
described.

On Jun 4, 9:26 pm, Shay Banon [shay.ba...@elasticsearch.com](mailto:shay.ba...@elasticsearch.com) wrote:

> No it won't, all fields will not be stored by default.
> 
> On Saturday, June 4, 2011 at 9:25 PM, slavag wrote:
> 
> > Btw, when I used default-mapping.json and put there:  
> > {  
> > "TEST" : {  
> > "\_source" : {"enabled" : false}  
> > }  
> > }
> 
> > It worked and all fields are stored by default, should it work in this  
> > way ?
> 
> > P.S. Still have  
> > On Jun 4, 9:21 pm, Shay Banon \<[shay.ba...@elasticsearch.com](mailto:shay.ba...@elasticsearch.com) ([http://elasticsearch.com](http://elasticsearch.com))\> wrote:
> > 
> > > You can use dynamic templates to try and define which fields will be stored based on some matching scheme:[Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/reference/mapping/root-object-type)....
> 
> > > On Saturday, June 4, 2011 at 9:19 PM, slavag wrote:
> > > 
> > > > That what I'm trying to understand, I read this section and still  
> > > > confused, when I'm using such mapping (not dynamic) and then new  
> > > > fields are cumming - it means I need explicitly to create a mapping  
> > > > for them ? Or there other way to make mapping dynamic after once I  
> > > > used static mapping (for \_source).
> 
> > > > Best Regards.
> 
> > > > On Jun 4, 9:14 pm, Shay Banon \<[shay.ba...@elasticsearch.com](mailto:shay.ba...@elasticsearch.com) ([http://elasticsearch.com](http://elasticsearch.com))\> wrote:
> > > > 
> > > > > You need to set store to yes in hte mapping for the relevant fields you want to retrieve. Check the mappings section in the guide.
> 
> > > > > On Saturday, June 4, 2011 at 9:09 PM, slavag wrote:
> > > > > 
> > > > > > Hi Shay, thank for a quick response,  
> > > > > > What do you mean when saying to explicitly store specific fields , I'm  
> > > > > > putting them into to JsonBuilder (in the search I do ask for them) ?
> 
> > > > > > Best Regards.
> 
> > > > > > On Jun 4, 7:47 pm, Shay Banon \<[shay.ba...@elasticsearch.com](mailto:shay.ba...@elasticsearch.com) ([http://elasticsearch.com](http://elasticsearch.com)) ([http://elasticsearch.com](http://elasticsearch.com))\> wrote:
> > > > > > 
> > > > > > > If you don't store the source, then you need to explicitly store specific fields (and ask for them in the search request) if you want them. It usually makes sense to use the \_source field then storing specific fields separately.
> 
> > > > > > > On Saturday, June 4, 2011 at 5:55 PM, slavag wrote:
> > > > > > > 
> > > > > > > > Hi,  
> > > > > > > > I'm trying to disable \_source field, using this:  
> > > > > > > > XContentBuilder data = jsonBuilder().startObject()  
> > > > > > > > .startObject("type")  
> > > > > > > > .startObject("\_source")  
> > > > > > > > .field("enabled", false)  
> > > > > > > > .endObject()  
> > > > > > > > .endObject()  
> > > > > > > > .endObject();
> 
> > > > > > > > client.admin().indices().ccreate(new  
> > > > > > > > CreateIndexRequest("index").mapping("type", data ));  
> > > > > > > > And looks like \_source is indeed not stored.
> 
> > > > > > > > Then I'm doing index with:
> 
> > > > > > > > XContentBuilder jsonBuilder = XContentFactory.jsonBuilder();  
> > > > > > > > jsonBuilder.startObject();  
> > > > > > > > jsonBuilder.field(FROMFIELD,addr.toString());  
> > > > > > > > jsonBuilder.field(RECIPIENTFIELD,addr.toString());  
> > > > > > > > jsonBuilder.field(SUBJECTFIELD,message.getSubject());  
> > > > > > > > jsonBuilder.field("bckdate",backuptimstamp);  
> > > > > > > > jsonBuilder.endObject();
> 
> > > > > > > > IndexRequestBuilder indexRequest =  
> > > > > > > > client.prepareIndex(this.tenant,this.type,id).setSource(jsonBuilder);  
> > > > > > > > IndexResponse response = indexRequest.execute().actionGet();
> 
> > > > > > > > The search result returns hits, without source field but as well  
> > > > > > > > without any other field , even on search I'm adding those fields.
> 
> > > > > > > > Looks like schema is not updated, the question after such a manual  
> > > > > > > > mapping, should schema be updated on index with new fields ?
> 
> > > > > > > > Thank You and Best Regards.

---

<div class="post-metadata">

### Author: ![kimchy](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/kimchy/32/44952_2.png) [@kimchy](https://discuss.elastic.co/u/kimchy)
#### Post date: [June 4, 2011, 6:28pm UTC](https://discuss.elastic.co/t/mapping-and-dynamic-mapping/4554/10 "2011-06-04T18:28:16Z")

</div>

No it won't.

On Saturday, June 4, 2011 at 9:27 PM, slavag wrote:

> Strange, as I did this on clean elasticsearch and it work as I  
> described.
> 
> On Jun 4, 9:26 pm, Shay Banon \<[shay.ba...@elasticsearch.com](mailto:shay.ba...@elasticsearch.com) ([http://elasticsearch.com](http://elasticsearch.com))\> wrote:
> 
> > No it won't, all fields will not be stored by default.
> > 
> > On Saturday, June 4, 2011 at 9:25 PM, slavag wrote:
> > 
> > > Btw, when I used default-mapping.json and put there:  
> > > {  
> > > "TEST" : {  
> > > "\_source" : {"enabled" : false}  
> > > }  
> > > }
> > 
> > > It worked and all fields are stored by default, should it work in this  
> > > way ?
> > 
> > > P.S. Still have  
> > > On Jun 4, 9:21 pm, Shay Banon \<[shay.ba...@elasticsearch.com](mailto:shay.ba...@elasticsearch.com) ([http://elasticsearch.com](http://elasticsearch.com))\> wrote:
> > > 
> > > > You can use dynamic templates to try and define which fields will be stored based on some matching scheme:[Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/reference/mapping/root-object-type)....
> > 
> > > > On Saturday, June 4, 2011 at 9:19 PM, slavag wrote:
> > > > 
> > > > > That what I'm trying to understand, I read this section and still  
> > > > > confused, when I'm using such mapping (not dynamic) and then new  
> > > > > fields are cumming - it means I need explicitly to create a mapping  
> > > > > for them ? Or there other way to make mapping dynamic after once I  
> > > > > used static mapping (for \_source).
> > 
> > > > > Best Regards.
> > 
> > > > > On Jun 4, 9:14 pm, Shay Banon \<[shay.ba...@elasticsearch.com](mailto:shay.ba...@elasticsearch.com) ([http://elasticsearch.com](http://elasticsearch.com))\> wrote:
> > > > > 
> > > > > > You need to set store to yes in hte mapping for the relevant fields you want to retrieve. Check the mappings section in the guide.
> > 
> > > > > > On Saturday, June 4, 2011 at 9:09 PM, slavag wrote:
> > > > > > 
> > > > > > > Hi Shay, thank for a quick response,  
> > > > > > > What do you mean when saying to explicitly store specific fields , I'm  
> > > > > > > putting them into to JsonBuilder (in the search I do ask for them) ?
> > 
> > > > > > > Best Regards.
> > 
> > > > > > > On Jun 4, 7:47 pm, Shay Banon \<[shay.ba...@elasticsearch.com](mailto:shay.ba...@elasticsearch.com) ([http://elasticsearch.com](http://elasticsearch.com)) ([http://elasticsearch.com](http://elasticsearch.com))\> wrote:
> > > > > > > 
> > > > > > > > If you don't store the source, then you need to explicitly store specific fields (and ask for them in the search request) if you want them. It usually makes sense to use the \_source field then storing specific fields separately.
> > 
> > > > > > > > On Saturday, June 4, 2011 at 5:55 PM, slavag wrote:
> > > > > > > > 
> > > > > > > > > Hi,  
> > > > > > > > > I'm trying to disable \_source field, using this:  
> > > > > > > > > XContentBuilder data = jsonBuilder().startObject()  
> > > > > > > > > .startObject("type")  
> > > > > > > > > .startObject("\_source")  
> > > > > > > > > .field("enabled", false)  
> > > > > > > > > .endObject()  
> > > > > > > > > .endObject()  
> > > > > > > > > .endObject();
> > 
> > > > > > > > > client.admin().indices().ccreate(new  
> > > > > > > > > CreateIndexRequest("index").mapping("type", data ));  
> > > > > > > > > And looks like \_source is indeed not stored.
> > 
> > > > > > > > > Then I'm doing index with:
> > 
> > > > > > > > > XContentBuilder jsonBuilder = XContentFactory.jsonBuilder();  
> > > > > > > > > jsonBuilder.startObject();  
> > > > > > > > > jsonBuilder.field(FROMFIELD,addr.toString());  
> > > > > > > > > jsonBuilder.field(RECIPIENTFIELD,addr.toString());  
> > > > > > > > > jsonBuilder.field(SUBJECTFIELD,message.getSubject());  
> > > > > > > > > jsonBuilder.field("bckdate",backuptimstamp);  
> > > > > > > > > jsonBuilder.endObject();
> > 
> > > > > > > > > IndexRequestBuilder indexRequest =  
> > > > > > > > > client.prepareIndex(this.tenant,this.type,id).setSource(jsonBuilder);  
> > > > > > > > > IndexResponse response = indexRequest.execute().actionGet();
> > 
> > > > > > > > > The search result returns hits, without source field but as well  
> > > > > > > > > without any other field , even on search I'm adding those fields.
> > 
> > > > > > > > > Looks like schema is not updated, the question after such a manual  
> > > > > > > > > mapping, should schema be updated on index with new fields ?
> > 
> > > > > > > > > Thank You and Best Regards.

---

<div class="post-metadata">

### Author: ![Slava\_G](https://avatars.discourse-cdn.com/v4/letter/s/e9c0ed/32.png) [@Slava\_G](https://discuss.elastic.co/u/Slava_G)
#### Post date: [June 4, 2011, 6:31pm UTC](https://discuss.elastic.co/t/mapping-and-dynamic-mapping/4554/11 "2011-06-04T18:31:16Z")

</div>

Ok, may be I'm wrong.

Last question, to make a compression on \_source, should I also use  
"static" mapping or default-mapping.json or there other way so tell to  
elasticsearch to compress it ?

On Jun 4, 9:28 pm, Shay Banon [shay.ba...@elasticsearch.com](mailto:shay.ba...@elasticsearch.com) wrote:

> No it won't.
> 
> On Saturday, June 4, 2011 at 9:27 PM, slavag wrote:
> 
> > Strange, as I did this on clean elasticsearch and it work as I  
> > described.
> 
> > On Jun 4, 9:26 pm, Shay Banon \<[shay.ba...@elasticsearch.com](mailto:shay.ba...@elasticsearch.com) ([http://elasticsearch.com](http://elasticsearch.com))\> wrote:
> > 
> > > No it won't, all fields will not be stored by default.
> 
> > > On Saturday, June 4, 2011 at 9:25 PM, slavag wrote:
> > > 
> > > > Btw, when I used default-mapping.json and put there:  
> > > > {  
> > > > "TEST" : {  
> > > > "\_source" : {"enabled" : false}  
> > > > }  
> > > > }
> 
> > > > It worked and all fields are stored by default, should it work in this  
> > > > way ?
> 
> > > > P.S. Still have  
> > > > On Jun 4, 9:21 pm, Shay Banon \<[shay.ba...@elasticsearch.com](mailto:shay.ba...@elasticsearch.com) ([http://elasticsearch.com](http://elasticsearch.com))\> wrote:
> > > > 
> > > > > You can use dynamic templates to try and define which fields will be stored based on some matching scheme:[Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/reference/mapping/root-object-type)....
> 
> > > > > On Saturday, June 4, 2011 at 9:19 PM, slavag wrote:
> > > > > 
> > > > > > That what I'm trying to understand, I read this section and still  
> > > > > > confused, when I'm using such mapping (not dynamic) and then new  
> > > > > > fields are cumming - it means I need explicitly to create a mapping  
> > > > > > for them ? Or there other way to make mapping dynamic after once I  
> > > > > > used static mapping (for \_source).
> 
> > > > > > Best Regards.
> 
> > > > > > On Jun 4, 9:14 pm, Shay Banon \<[shay.ba...@elasticsearch.com](mailto:shay.ba...@elasticsearch.com) ([http://elasticsearch.com](http://elasticsearch.com))\> wrote:
> > > > > > 
> > > > > > > You need to set store to yes in hte mapping for the relevant fields you want to retrieve. Check the mappings section in the guide.
> 
> > > > > > > On Saturday, June 4, 2011 at 9:09 PM, slavag wrote:
> > > > > > > 
> > > > > > > > Hi Shay, thank for a quick response,  
> > > > > > > > What do you mean when saying to explicitly store specific fields , I'm  
> > > > > > > > putting them into to JsonBuilder (in the search I do ask for them) ?
> 
> > > > > > > > Best Regards.
> 
> > > > > > > > On Jun 4, 7:47 pm, Shay Banon \<[shay.ba...@elasticsearch.com](mailto:shay.ba...@elasticsearch.com) ([http://elasticsearch.com](http://elasticsearch.com)) ([http://elasticsearch.com](http://elasticsearch.com))\> wrote:
> > > > > > > > 
> > > > > > > > > If you don't store the source, then you need to explicitly store specific fields (and ask for them in the search request) if you want them. It usually makes sense to use the \_source field then storing specific fields separately.
> 
> > > > > > > > > On Saturday, June 4, 2011 at 5:55 PM, slavag wrote:
> > > > > > > > > 
> > > > > > > > > > Hi,  
> > > > > > > > > > I'm trying to disable \_source field, using this:  
> > > > > > > > > > XContentBuilder data = jsonBuilder().startObject()  
> > > > > > > > > > .startObject("type")  
> > > > > > > > > > .startObject("\_source")  
> > > > > > > > > > .field("enabled", false)  
> > > > > > > > > > .endObject()  
> > > > > > > > > > .endObject()  
> > > > > > > > > > .endObject();
> 
> > > > > > > > > > client.admin().indices().ccreate(new  
> > > > > > > > > > CreateIndexRequest("index").mapping("type", data ));  
> > > > > > > > > > And looks like \_source is indeed not stored.
> 
> > > > > > > > > > Then I'm doing index with:
> 
> > > > > > > > > > XContentBuilder jsonBuilder = XContentFactory.jsonBuilder();  
> > > > > > > > > > jsonBuilder.startObject();  
> > > > > > > > > > jsonBuilder.field(FROMFIELD,addr.toString());  
> > > > > > > > > > jsonBuilder.field(RECIPIENTFIELD,addr.toString());  
> > > > > > > > > > jsonBuilder.field(SUBJECTFIELD,message.getSubject());  
> > > > > > > > > > jsonBuilder.field("bckdate",backuptimstamp);  
> > > > > > > > > > jsonBuilder.endObject();
> 
> > > > > > > > > > IndexRequestBuilder indexRequest =  
> > > > > > > > > > client.prepareIndex(this.tenant,this.type,id).setSource(jsonBuilder);  
> > > > > > > > > > IndexResponse response = indexRequest.execute().actionGet();
> 
> > > > > > > > > > The search result returns hits, without source field but as well  
> > > > > > > > > > without any other field , even on search I'm adding those fields.
> 
> > > > > > > > > > Looks like schema is not updated, the question after such a manual  
> > > > > > > > > > mapping, should schema be updated on index with new fields ?
> 
> > > > > > > > > > Thank You and Best Regards.

---

<div class="post-metadata">

### Author: ![kimchy](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/kimchy/32/44952_2.png) [@kimchy](https://discuss.elastic.co/u/kimchy)
#### Post date: [June 4, 2011, 6:32pm UTC](https://discuss.elastic.co/t/mapping-and-dynamic-mapping/4554/12 "2011-06-04T18:32:48Z")

</div>

You can use the default-mapping.json option, but then you need to apply it to all nodes. Another option is to use index template, and have the _default_ mapping type applied with compression to source (which is more of an API way to do it).

On Saturday, June 4, 2011 at 9:31 PM, slavag wrote:

> Ok, may be I'm wrong.
> 
> Last question, to make a compression on \_source, should I also use  
> "static" mapping or default-mapping.json or there other way so tell to  
> elasticsearch to compress it ?
> 
> On Jun 4, 9:28 pm, Shay Banon \<[shay.ba...@elasticsearch.com](mailto:shay.ba...@elasticsearch.com) ([http://elasticsearch.com](http://elasticsearch.com))\> wrote:
> 
> > No it won't.
> > 
> > On Saturday, June 4, 2011 at 9:27 PM, slavag wrote:
> > 
> > > Strange, as I did this on clean elasticsearch and it work as I  
> > > described.
> > 
> > > On Jun 4, 9:26 pm, Shay Banon \<[shay.ba...@elasticsearch.com](mailto:shay.ba...@elasticsearch.com) ([http://elasticsearch.com](http://elasticsearch.com))\> wrote:
> > > 
> > > > No it won't, all fields will not be stored by default.
> > 
> > > > On Saturday, June 4, 2011 at 9:25 PM, slavag wrote:
> > > > 
> > > > > Btw, when I used default-mapping.json and put there:  
> > > > > {  
> > > > > "TEST" : {  
> > > > > "\_source" : {"enabled" : false}  
> > > > > }  
> > > > > }
> > 
> > > > > It worked and all fields are stored by default, should it work in this  
> > > > > way ?
> > 
> > > > > P.S. Still have  
> > > > > On Jun 4, 9:21 pm, Shay Banon \<[shay.ba...@elasticsearch.com](mailto:shay.ba...@elasticsearch.com) ([http://elasticsearch.com](http://elasticsearch.com))\> wrote:
> > > > > 
> > > > > > You can use dynamic templates to try and define which fields will be stored based on some matching scheme:[Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/reference/mapping/root-object-type)....
> > 
> > > > > > On Saturday, June 4, 2011 at 9:19 PM, slavag wrote:
> > > > > > 
> > > > > > > That what I'm trying to understand, I read this section and still  
> > > > > > > confused, when I'm using such mapping (not dynamic) and then new  
> > > > > > > fields are cumming - it means I need explicitly to create a mapping  
> > > > > > > for them ? Or there other way to make mapping dynamic after once I  
> > > > > > > used static mapping (for \_source).
> > 
> > > > > > > Best Regards.
> > 
> > > > > > > On Jun 4, 9:14 pm, Shay Banon \<[shay.ba...@elasticsearch.com](mailto:shay.ba...@elasticsearch.com) ([http://elasticsearch.com](http://elasticsearch.com))\> wrote:
> > > > > > > 
> > > > > > > > You need to set store to yes in hte mapping for the relevant fields you want to retrieve. Check the mappings section in the guide.
> > 
> > > > > > > > On Saturday, June 4, 2011 at 9:09 PM, slavag wrote:
> > > > > > > > 
> > > > > > > > > Hi Shay, thank for a quick response,  
> > > > > > > > > What do you mean when saying to explicitly store specific fields , I'm  
> > > > > > > > > putting them into to JsonBuilder (in the search I do ask for them) ?
> > 
> > > > > > > > > Best Regards.
> > 
> > > > > > > > > On Jun 4, 7:47 pm, Shay Banon \<[shay.ba...@elasticsearch.com](mailto:shay.ba...@elasticsearch.com) ([http://elasticsearch.com](http://elasticsearch.com)) ([http://elasticsearch.com](http://elasticsearch.com))\> wrote:
> > > > > > > > > 
> > > > > > > > > > If you don't store the source, then you need to explicitly store specific fields (and ask for them in the search request) if you want them. It usually makes sense to use the \_source field then storing specific fields separately.
> > 
> > > > > > > > > > On Saturday, June 4, 2011 at 5:55 PM, slavag wrote:
> > > > > > > > > > 
> > > > > > > > > > > Hi,  
> > > > > > > > > > > I'm trying to disable \_source field, using this:  
> > > > > > > > > > > XContentBuilder data = jsonBuilder().startObject()  
> > > > > > > > > > > .startObject("type")  
> > > > > > > > > > > .startObject("\_source")  
> > > > > > > > > > > .field("enabled", false)  
> > > > > > > > > > > .endObject()  
> > > > > > > > > > > .endObject()  
> > > > > > > > > > > .endObject();
> > 
> > > > > > > > > > > client.admin().indices().ccreate(new  
> > > > > > > > > > > CreateIndexRequest("index").mapping("type", data ));  
> > > > > > > > > > > And looks like \_source is indeed not stored.
> > 
> > > > > > > > > > > Then I'm doing index with:
> > 
> > > > > > > > > > > XContentBuilder jsonBuilder = XContentFactory.jsonBuilder();  
> > > > > > > > > > > jsonBuilder.startObject();  
> > > > > > > > > > > jsonBuilder.field(FROMFIELD,addr.toString());  
> > > > > > > > > > > jsonBuilder.field(RECIPIENTFIELD,addr.toString());  
> > > > > > > > > > > jsonBuilder.field(SUBJECTFIELD,message.getSubject());  
> > > > > > > > > > > jsonBuilder.field("bckdate",backuptimstamp);  
> > > > > > > > > > > jsonBuilder.endObject();
> > 
> > > > > > > > > > > IndexRequestBuilder indexRequest =  
> > > > > > > > > > > client.prepareIndex(this.tenant,this.type,id).setSource(jsonBuilder);  
> > > > > > > > > > > IndexResponse response = indexRequest.execute().actionGet();
> > 
> > > > > > > > > > > The search result returns hits, without source field but as well  
> > > > > > > > > > > without any other field , even on search I'm adding those fields.
> > 
> > > > > > > > > > > Looks like schema is not updated, the question after such a manual  
> > > > > > > > > > > mapping, should schema be updated on index with new fields ?
> > 
> > > > > > > > > > > Thank You and Best Regards.

---

<div class="post-metadata">

### Author: ![Slava\_G](https://avatars.discourse-cdn.com/v4/letter/s/e9c0ed/32.png) [@Slava\_G](https://discuss.elastic.co/u/Slava_G)
#### Post date: [June 4, 2011, 6:38pm UTC](https://discuss.elastic.co/t/mapping-and-dynamic-mapping/4554/13 "2011-06-04T18:38:26Z")

</div>

Thank You, where can I read about index template ?

On Jun 4, 9:32 pm, Shay Banon [shay.ba...@elasticsearch.com](mailto:shay.ba...@elasticsearch.com) wrote:

> You can use the default-mapping.json option, but then you need to apply it to all nodes. Another option is to use index template, and have the _default_ mapping type applied with compression to source (which is more of an API way to do it).
> 
> On Saturday, June 4, 2011 at 9:31 PM, slavag wrote:
> 
> > Ok, may be I'm wrong.
> 
> > Last question, to make a compression on \_source, should I also use  
> > "static" mapping or default-mapping.json or there other way so tell to  
> > elasticsearch to compress it ?
> 
> > On Jun 4, 9:28 pm, Shay Banon \<[shay.ba...@elasticsearch.com](mailto:shay.ba...@elasticsearch.com) ([http://elasticsearch.com](http://elasticsearch.com))\> wrote:
> > 
> > > No it won't.
> 
> > > On Saturday, June 4, 2011 at 9:27 PM, slavag wrote:
> > > 
> > > > Strange, as I did this on clean elasticsearch and it work as I  
> > > > described.
> 
> > > > On Jun 4, 9:26 pm, Shay Banon \<[shay.ba...@elasticsearch.com](mailto:shay.ba...@elasticsearch.com) ([http://elasticsearch.com](http://elasticsearch.com))\> wrote:
> > > > 
> > > > > No it won't, all fields will not be stored by default.
> 
> > > > > On Saturday, June 4, 2011 at 9:25 PM, slavag wrote:
> > > > > 
> > > > > > Btw, when I used default-mapping.json and put there:  
> > > > > > {  
> > > > > > "TEST" : {  
> > > > > > "\_source" : {"enabled" : false}  
> > > > > > }  
> > > > > > }
> 
> > > > > > It worked and all fields are stored by default, should it work in this  
> > > > > > way ?
> 
> > > > > > P.S. Still have  
> > > > > > On Jun 4, 9:21 pm, Shay Banon \<[shay.ba...@elasticsearch.com](mailto:shay.ba...@elasticsearch.com) ([http://elasticsearch.com](http://elasticsearch.com))\> wrote:
> > > > > > 
> > > > > > > You can use dynamic templates to try and define which fields will be stored based on some matching scheme:[Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/reference/mapping/root-object-type)....
> 
> > > > > > > On Saturday, June 4, 2011 at 9:19 PM, slavag wrote:
> > > > > > > 
> > > > > > > > That what I'm trying to understand, I read this section and still  
> > > > > > > > confused, when I'm using such mapping (not dynamic) and then new  
> > > > > > > > fields are cumming - it means I need explicitly to create a mapping  
> > > > > > > > for them ? Or there other way to make mapping dynamic after once I  
> > > > > > > > used static mapping (for \_source).
> 
> > > > > > > > Best Regards.
> 
> > > > > > > > On Jun 4, 9:14 pm, Shay Banon \<[shay.ba...@elasticsearch.com](mailto:shay.ba...@elasticsearch.com) ([http://elasticsearch.com](http://elasticsearch.com))\> wrote:
> > > > > > > > 
> > > > > > > > > You need to set store to yes in hte mapping for the relevant fields you want to retrieve. Check the mappings section in the guide.
> 
> > > > > > > > > On Saturday, June 4, 2011 at 9:09 PM, slavag wrote:
> > > > > > > > > 
> > > > > > > > > > Hi Shay, thank for a quick response,  
> > > > > > > > > > What do you mean when saying to explicitly store specific fields , I'm  
> > > > > > > > > > putting them into to JsonBuilder (in the search I do ask for them) ?
> 
> > > > > > > > > > Best Regards.
> 
> > > > > > > > > > On Jun 4, 7:47 pm, Shay Banon \<[shay.ba...@elasticsearch.com](mailto:shay.ba...@elasticsearch.com) ([http://elasticsearch.com](http://elasticsearch.com)) ([http://elasticsearch.com](http://elasticsearch.com))\> wrote:
> > > > > > > > > > 
> > > > > > > > > > > If you don't store the source, then you need to explicitly store specific fields (and ask for them in the search request) if you want them. It usually makes sense to use the \_source field then storing specific fields separately.
> 
> > > > > > > > > > > On Saturday, June 4, 2011 at 5:55 PM, slavag wrote:
> > > > > > > > > > > 
> > > > > > > > > > > > Hi,  
> > > > > > > > > > > > I'm trying to disable \_source field, using this:  
> > > > > > > > > > > > XContentBuilder data = jsonBuilder().startObject()  
> > > > > > > > > > > > .startObject("type")  
> > > > > > > > > > > > .startObject("\_source")  
> > > > > > > > > > > > .field("enabled", false)  
> > > > > > > > > > > > .endObject()  
> > > > > > > > > > > > .endObject()  
> > > > > > > > > > > > .endObject();
> 
> > > > > > > > > > > > client.admin().indices().ccreate(new  
> > > > > > > > > > > > CreateIndexRequest("index").mapping("type", data ));  
> > > > > > > > > > > > And looks like \_source is indeed not stored.
> 
> > > > > > > > > > > > Then I'm doing index with:
> 
> > > > > > > > > > > > XContentBuilder jsonBuilder = XContentFactory.jsonBuilder();  
> > > > > > > > > > > > jsonBuilder.startObject();  
> > > > > > > > > > > > jsonBuilder.field(FROMFIELD,addr.toString());  
> > > > > > > > > > > > jsonBuilder.field(RECIPIENTFIELD,addr.toString());  
> > > > > > > > > > > > jsonBuilder.field(SUBJECTFIELD,message.getSubject());  
> > > > > > > > > > > > jsonBuilder.field("bckdate",backuptimstamp);  
> > > > > > > > > > > > jsonBuilder.endObject();
> 
> > > > > > > > > > > > IndexRequestBuilder indexRequest =  
> > > > > > > > > > > > client.prepareIndex(this.tenant,this.type,id).setSource(jsonBuilder);  
> > > > > > > > > > > > IndexResponse response = indexRequest.execute().actionGet();
> 
> > > > > > > > > > > > The search result returns hits, without source field but as well  
> > > > > > > > > > > > without any other field , even on search I'm adding those fields.
> 
> > > > > > > > > > > > Looks like schema is not updated, the question after such a manual  
> > > > > > > > > > > > mapping, should schema be updated on index with new fields ?
> 
> > > > > > > > > > > > Thank You and Best Regards.

---

<div class="post-metadata">

### Author: ![kimchy](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/kimchy/32/44952_2.png) [@kimchy](https://discuss.elastic.co/u/kimchy)
#### Post date: [June 4, 2011, 6:39pm UTC](https://discuss.elastic.co/t/mapping-and-dynamic-mapping/4554/14 "2011-06-04T18:39:11Z")

</div>

> **[Elasticsearch Platform — Find real-time answers at scale](https://www.elastic.co)**
>
> Power insights and outcomes with the Elasticsearch Platform and AI. See into your data and find answers that matter with enterprise solutions designed to help you build, observe, and protect. Try Elasticsearch free today.

On Saturday, June 4, 2011 at 9:38 PM, slavag wrote:

> Thank You, where can I read about index template ?
> 
> On Jun 4, 9:32 pm, Shay Banon \<[shay.ba...@elasticsearch.com](mailto:shay.ba...@elasticsearch.com) ([http://elasticsearch.com](http://elasticsearch.com))\> wrote:
> 
> > You can use the default-mapping.json option, but then you need to apply it to all nodes. Another option is to use index template, and have the _default_ mapping type applied with compression to source (which is more of an API way to do it).
> > 
> > On Saturday, June 4, 2011 at 9:31 PM, slavag wrote:
> > 
> > > Ok, may be I'm wrong.
> > 
> > > Last question, to make a compression on \_source, should I also use  
> > > "static" mapping or default-mapping.json or there other way so tell to  
> > > elasticsearch to compress it ?
> > 
> > > On Jun 4, 9:28 pm, Shay Banon \<[shay.ba...@elasticsearch.com](mailto:shay.ba...@elasticsearch.com) ([http://elasticsearch.com](http://elasticsearch.com))\> wrote:
> > > 
> > > > No it won't.
> > 
> > > > On Saturday, June 4, 2011 at 9:27 PM, slavag wrote:
> > > > 
> > > > > Strange, as I did this on clean elasticsearch and it work as I  
> > > > > described.
> > 
> > > > > On Jun 4, 9:26 pm, Shay Banon \<[shay.ba...@elasticsearch.com](mailto:shay.ba...@elasticsearch.com) ([http://elasticsearch.com](http://elasticsearch.com))\> wrote:
> > > > > 
> > > > > > No it won't, all fields will not be stored by default.
> > 
> > > > > > On Saturday, June 4, 2011 at 9:25 PM, slavag wrote:
> > > > > > 
> > > > > > > Btw, when I used default-mapping.json and put there:  
> > > > > > > {  
> > > > > > > "TEST" : {  
> > > > > > > "\_source" : {"enabled" : false}  
> > > > > > > }  
> > > > > > > }
> > 
> > > > > > > It worked and all fields are stored by default, should it work in this  
> > > > > > > way ?
> > 
> > > > > > > P.S. Still have  
> > > > > > > On Jun 4, 9:21 pm, Shay Banon \<[shay.ba...@elasticsearch.com](mailto:shay.ba...@elasticsearch.com) ([http://elasticsearch.com](http://elasticsearch.com))\> wrote:
> > > > > > > 
> > > > > > > > You can use dynamic templates to try and define which fields will be stored based on some matching scheme:[Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/reference/mapping/root-object-type)....
> > 
> > > > > > > > On Saturday, June 4, 2011 at 9:19 PM, slavag wrote:
> > > > > > > > 
> > > > > > > > > That what I'm trying to understand, I read this section and still  
> > > > > > > > > confused, when I'm using such mapping (not dynamic) and then new  
> > > > > > > > > fields are cumming - it means I need explicitly to create a mapping  
> > > > > > > > > for them ? Or there other way to make mapping dynamic after once I  
> > > > > > > > > used static mapping (for \_source).
> > 
> > > > > > > > > Best Regards.
> > 
> > > > > > > > > On Jun 4, 9:14 pm, Shay Banon \<[shay.ba...@elasticsearch.com](mailto:shay.ba...@elasticsearch.com) ([http://elasticsearch.com](http://elasticsearch.com))\> wrote:
> > > > > > > > > 
> > > > > > > > > > You need to set store to yes in hte mapping for the relevant fields you want to retrieve. Check the mappings section in the guide.
> > 
> > > > > > > > > > On Saturday, June 4, 2011 at 9:09 PM, slavag wrote:
> > > > > > > > > > 
> > > > > > > > > > > Hi Shay, thank for a quick response,  
> > > > > > > > > > > What do you mean when saying to explicitly store specific fields , I'm  
> > > > > > > > > > > putting them into to JsonBuilder (in the search I do ask for them) ?
> > 
> > > > > > > > > > > Best Regards.
> > 
> > > > > > > > > > > On Jun 4, 7:47 pm, Shay Banon \<[shay.ba...@elasticsearch.com](mailto:shay.ba...@elasticsearch.com) ([http://elasticsearch.com](http://elasticsearch.com)) ([http://elasticsearch.com](http://elasticsearch.com))\> wrote:
> > > > > > > > > > > 
> > > > > > > > > > > > If you don't store the source, then you need to explicitly store specific fields (and ask for them in the search request) if you want them. It usually makes sense to use the \_source field then storing specific fields separately.
> > 
> > > > > > > > > > > > On Saturday, June 4, 2011 at 5:55 PM, slavag wrote:
> > > > > > > > > > > > 
> > > > > > > > > > > > > Hi,  
> > > > > > > > > > > > > I'm trying to disable \_source field, using this:  
> > > > > > > > > > > > > XContentBuilder data = jsonBuilder().startObject()  
> > > > > > > > > > > > > .startObject("type")  
> > > > > > > > > > > > > .startObject("\_source")  
> > > > > > > > > > > > > .field("enabled", false)  
> > > > > > > > > > > > > .endObject()  
> > > > > > > > > > > > > .endObject()  
> > > > > > > > > > > > > .endObject();
> > 
> > > > > > > > > > > > > client.admin().indices().ccreate(new  
> > > > > > > > > > > > > CreateIndexRequest("index").mapping("type", data ));  
> > > > > > > > > > > > > And looks like \_source is indeed not stored.
> > 
> > > > > > > > > > > > > Then I'm doing index with:
> > 
> > > > > > > > > > > > > XContentBuilder jsonBuilder = XContentFactory.jsonBuilder();  
> > > > > > > > > > > > > jsonBuilder.startObject();  
> > > > > > > > > > > > > jsonBuilder.field(FROMFIELD,addr.toString());  
> > > > > > > > > > > > > jsonBuilder.field(RECIPIENTFIELD,addr.toString());  
> > > > > > > > > > > > > jsonBuilder.field(SUBJECTFIELD,message.getSubject());  
> > > > > > > > > > > > > jsonBuilder.field("bckdate",backuptimstamp);  
> > > > > > > > > > > > > jsonBuilder.endObject();
> > 
> > > > > > > > > > > > > IndexRequestBuilder indexRequest =  
> > > > > > > > > > > > > client.prepareIndex(this.tenant,this.type,id).setSource(jsonBuilder);  
> > > > > > > > > > > > > IndexResponse response = indexRequest.execute().actionGet();
> > 
> > > > > > > > > > > > > The search result returns hits, without source field but as well  
> > > > > > > > > > > > > without any other field , even on search I'm adding those fields.
> > 
> > > > > > > > > > > > > Looks like schema is not updated, the question after such a manual  
> > > > > > > > > > > > > mapping, should schema be updated on index with new fields ?
> > 
> > > > > > > > > > > > > Thank You and Best Regards.

---

<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, 4:04am UTC](https://discuss.elastic.co/t/mapping-and-dynamic-mapping/4554/15 "2017-07-06T04:04:34Z")

</div>


