# Is this code correct for storing fields?

**URL:** https://discuss.elastic.co/t/is-this-code-correct-for-storing-fields/8081
**Category:** Elasticsearch
**Created:** [June 13, 2012, 11:40am UTC](https://discuss.elastic.co/t/is-this-code-correct-for-storing-fields/8081 "2012-06-13T11:40:34Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![Saurabh](https://avatars.discourse-cdn.com/v4/letter/s/ee7513/32.png) [@Saurabh](https://discuss.elastic.co/u/Saurabh)
#### Post date: [June 13, 2012, 11:40am UTC](https://discuss.elastic.co/t/is-this-code-correct-for-storing-fields/8081/1 "2012-06-13T11:40:34Z")

</div>

this a sample code, will it store the "message" field?

```
    IndexRequestBuilder req = client.prepareIndex("twitter", "tweet")
            .setSource(jsonBuilder()
                    .startObject()
                        .field("user", "kimchy")
                        .field("postDate", "12 June")
                        .field("message", "trying out Elastic Search")
                        .field("properties").startObject()
                        .field("message").startObject()
                        .field("store","yes")
                        .field("index","analyzed")
                        .endObject()
                        .endObject()
                    .endObject()
                  );
    bulkRequest.add(req);

```

Urgent Help needed.

---

<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 14, 2012, 9:32pm UTC](https://discuss.elastic.co/t/is-this-code-correct-for-storing-fields/8081/2 "2012-06-14T21:32:08Z")

</div>

The whole document is stored by default (under a special field called  
\_source), so yes, the message will be part of it.

On Wed, Jun 13, 2012 at 1:40 PM, Saurabh [saurabh.k1510@gmail.com](mailto:saurabh.k1510@gmail.com) wrote:

> this a sample code, will it store the "message" field?
> 
> ```
> IndexRequestBuilder req = client.prepareIndex("twitter", "tweet")
> .setSource(jsonBuilder()
> .startObject()
> .field("user", "kimchy")
> .field("postDate", "12 June")
> .field("message", "trying out Elastic Search")
> .field("properties").startObject()
> .field("message").startObject()
> .field("store","yes")
> .field("index","analyzed")
> .endObject()
> .endObject()
> .endObject()
> );
> bulkRequest.add(req);
> 
> ```
> 
> Urgent Help needed.

---

<div class="post-metadata">

### Author: ![Saurabh](https://avatars.discourse-cdn.com/v4/letter/s/ee7513/32.png) [@Saurabh](https://discuss.elastic.co/u/Saurabh)
#### Post date: [June 15, 2012, 3:47am UTC](https://discuss.elastic.co/t/is-this-code-correct-for-storing-fields/8081/3 "2012-06-15T03:47:08Z")

</div>

Thanks, but is there any way to check whether a field is stored or not, i  
mean not the \_source field, the fields which i store explicitly.

On Fri, Jun 15, 2012 at 3:02 AM, Shay Banon [kimchy@gmail.com](mailto:kimchy@gmail.com) wrote:

> The whole document is stored by default (under a special field called  
> \_source), so yes, the message will be part of it.
> 
> On Wed, Jun 13, 2012 at 1:40 PM, Saurabh [saurabh.k1510@gmail.com](mailto:saurabh.k1510@gmail.com) wrote:
> 
> > this a sample code, will it store the "message" field?
> > 
> > ```
> > IndexRequestBuilder req = client.prepareIndex("twitter", "tweet")
> > .setSource(jsonBuilder()
> > .startObject()
> > .field("user", "kimchy")
> > .field("postDate", "12 June")
> > .field("message", "trying out Elastic Search")
> > .field("properties").startObject()
> > .field("message").startObject()
> > .field("store","yes")
> > .field("index","analyzed")
> > .endObject()
> > .endObject()
> > .endObject()
> > );
> > bulkRequest.add(req);
> > 
> > ```
> > 
> > Urgent Help needed.

--  
Saurabh Kumar  
M.Sc (Mathematics) B.E (Computer Science)  
Birla Institute of Technology and Science-Pilani

---

<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:24am UTC](https://discuss.elastic.co/t/is-this-code-correct-for-storing-fields/8081/4 "2017-07-06T03:24:00Z")

</div>


