# Indexing using XContentBuilder

**URL:** <https://discuss.elastic.co/t/indexing-using-xcontentbuilder/40720>\
**Category:** Elasticsearch\
**Created:** [February 2, 2016, 11:47am UTC](https://discuss.elastic.co/t/indexing-using-xcontentbuilder/40720 "2016-02-02T11:47:17Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![sanju1323](https://avatars.discourse-cdn.com/v4/letter/s/5daacb/32.png) [@sanju1323](https://discuss.elastic.co/u/sanju1323)\
**Post date:** [February 2, 2016, 11:47am UTC](https://discuss.elastic.co/t/indexing-using-xcontentbuilder/40720/1 "2016-02-02T11:47:17Z")

</div>

Hi,

I got stuck at a point while indexing the data.

The format that I'm indexing the data is :  
(Code followed by the result)

```
 XContentFactory.jsonBuilder().startObject()
.startObject("tweet")
    .startObject("properties")
        .filed("name","lakshman")
        .startObject("message")
            .field("type", "string")
            .field("store", "yes")
            .field("index", "analyzed")
            .field("null_value", "na")
        .endObject()
    .endObject()
.endObject()

```

.endObject()

```
"tweet":{
	"name":"lakshman"
	"message"{
		"type", "string",
		"store", "yes",
		"index", "analyzed"
		"null_value", "na"
         }
    }

```

Now, If I index the record "tweet" again with different name like "name":"sanjay" and remaining data as same, then both the records should come like:

```
"tweet":{
        "name":"lakshman"
	"message"{
		"type", "string",
		"store", "yes",
		"index", "analyzed"
		"null_value", "na"
         }
	
	"name":"sanjay"
	"message"{
		"type", "string",
		"store", "yes",
		"index", "analyzed"
		"null_value", "na"
         }
   }

```

Is this possible. If yes, please help me in achieving this.

Thanks & Regards,  
Sanjay Reddy.

---

<div class="post-metadata">

**Author:** ![Geunmoon\_Oh](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/geunmoon_oh/32/7507_2.png) [@Geunmoon\_Oh](https://discuss.elastic.co/u/Geunmoon_Oh)\
**Post date:** [February 2, 2016, 2:50pm UTC](https://discuss.elastic.co/t/indexing-using-xcontentbuilder/40720/2 "2016-02-02T14:50:24Z")

</div>

how about using nested object field like below?

```
{
  "tweet": [
    {
      "name": "lakshman",
      "message": {
        "type": "string",
        "store": "yes",
        "index": "analyzed",
        "null_value": "na"
      }
    },
    {
      "name": "sanjay",
      "message": {
        "type": "string",
        "store": "yes",
        "index": "analyzed",
        "null_value": "na"
      }
    }
  ]
}
```

---

<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 5, 2017, 11:19pm UTC](https://discuss.elastic.co/t/indexing-using-xcontentbuilder/40720/3 "2017-07-05T23:19:38Z")

</div>


