# Array type inside Nested Index - unreadable response

**URL:** <https://discuss.elastic.co/t/array-type-inside-nested-index-unreadable-response/7225>\
**Category:** Elasticsearch\
**Created:** [April 4, 2012, 1:50pm UTC](https://discuss.elastic.co/t/array-type-inside-nested-index-unreadable-response/7225 "2012-04-04T13:50:03Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![manoj\_2](https://avatars.discourse-cdn.com/v4/letter/m/e0b2c6/32.png) [@manoj\_2](https://discuss.elastic.co/u/manoj_2)\
**Post date:** [April 4, 2012, 1:50pm UTC](https://discuss.elastic.co/t/array-type-inside-nested-index-unreadable-response/7225/1 "2012-04-04T13:50:03Z")

</div>

Hi,

I am working on a task which required to have an array of nested Index  
for a field, the mapping of which is given below

```
                       "eventnested":{
			"type" : "nested", "store" : "yes", "index" : "analyzed",

```

"omit\_norms" : "true",  
"include\_in\_parent":true,  
"properties":{  
"event\_type":{"type" : "string", "store" : "yes", "index" :  
"not\_analyzed", "omit\_norms" : "true"},  
"attributes":{  
"properties":{  
"event\_attribute\_name":{"type" : "string", "store" : "yes",  
"index" : "not\_analyzed", "omit\_norms" : "true"},  
"event\_attribute\_value":{"type" : "string", "store" : "yes",  
"index" : "not\_analyzed", "omit\_norms" : "true"}  
}  
},  
"event\_attribute\_instance":{"type" : "string", "store" : "yes",  
"precision\_step" : "0"}  
}  
}

I tried indexing data using a Curl with this mapping, which worked.  
But when I tried the same using Java API, the data was indexed  
wrong(unreadable). I have given below the snippet of the code I  
followed

XContentBuilder xb1 = XContentFactory.jsonBuilder().startObject();  
XContentBuilder xb2 = XContentFactory.jsonBuilder().startObject();

xb1.startArray("eventnested");  
for(int j=0;j\<2;j++)  
{  
xb2.field("event\_type",eventType);  
xb2.field("event\_attribute\_instance",eventInstance);  
xb2.startArray("attributes");  
for(int i=0;i\<2;i++)  
{  
XContentBuilder xb3 = XContentFactory.jsonBuilder().startObject();  
xb3.field("event\_attribute\_name", attrName);  
xb3.field("event\_attribute\_value", attrValue);  
xb2.value(xb3.copiedBytes());  
}  
xb1.value(xb2.copiedBytes());  
}

After indexing the data, when I read the response the data of the  
particular field looked like

"eventnested.event\_type":  
["eyJldmVudF90eXBlIjoiUXVvdGF0aW9uIiwiZXZlbnRfYXR0cmlidXRlX2luc3RhbmNlIjoiMSIsImF0dHJpYnV0ZXMiOlsiZXlKbGRtVnVkRjloZEhSeWFXSjFkR1ZmYm1GdFpTSTZJbkJsY25OdmJpQWlMQ0psZG1WdWRGOWhkSFJ5YVdKMWRHVmZkbUZzZFdVaU9pSkxZWGtnVFdGcmFIVmlaV3hoSW4wPSJdLCJhdHRyaWJ1dGVzIjpbImV5SmxkbVZ1ZEY5aGRIUnlhV0oxZEdWZmJtRnRaU0k2SW5GMWIzUmxJQ0lzSW1WMlpXNTBYMkYwZEhKcFluVjBaVjkyWVd4MVpTSTZJblJvWlNCaWIza2djbUZ3WldRZ2RHaGxJSEJoYVhJZ2IyNGdiblZ0WlhKdmRYTWdiMk5qWVhOcGIyNXpMQ0IzYVhSb0lIUm9aU0JzWVhSbGMzUWdhVzVqYVdSbGJuUWdZbVZwYm1jZ2IyNGdSbkpwWkdGNUluMD0iXX0=","eyJldmVudF90eXBlIjoiUXVvdGF0aW9uIiwiZXZlbnRfYXR0cmlidXRlX2luc3RhbmNlIjoiMSIsImF0dHJpYnV0ZXMiOlsiZXlKbGRtVnVkRjloZEhSeWFXSjFkR1ZmYm1GdFpTSTZJbkJsY25OdmJpQWlMQ0psZG1WdWRGOWhkSFJ5YVdKMWRHVmZkbUZzZFdVaU9pSkxZWGtnVFdGcmFIVmlaV3hoSW4wPSJdLCJhdHRyaWJ1dGVzIjpbImV5SmxkbVZ1ZEY5aGRIUnlhV0oxZEdWZmJtRnRaU0k2SW5GMWIzUmxJQ0lzSW1WMlpXNTBYMkYwZEhKcFluVjBaVjkyWVd4MVpTSTZJblJvWlNCMFpXVnVZV2RsY2lCb1lYTWdZbVZsYmlCd2JHRmpaV1FnYVc0Z1lTQnpZV1psZEhrZ2FHOXRaU0JoYm1RZ2QybHNiQ0JpWlNCamFHRnlaMlZrSUhkcGRHZ2djbUZ3WlNKOSJdfQ=="]}

I feel like the code is working very weird. Could anyone pls look  
above and show me a path

Thanks in advance!  
Regards,  
Manoj.

---

<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:** [April 4, 2012, 3:02pm UTC](https://discuss.elastic.co/t/array-type-inside-nested-index-unreadable-response/7225/2 "2012-04-04T15:02:56Z")

</div>

You are not building the data correctly, since you pass a binary value to  
the builder? Just use your favorite json generation library, you don't have  
to use the XContentBuilder (which actually is very similar to jackson  
generator).

On Wed, Apr 4, 2012 at 4:50 PM, Manoj [manokrrish@gmail.com](mailto:manokrrish@gmail.com) wrote:

> Hi,
> 
> I am working on a task which required to have an array of nested Index  
> for a field, the mapping of which is given below
> 
> ```
> "eventnested":{
> "type" : "nested", "store" : "yes", "index"
> 
> ```
> 
> : "analyzed",  
> "omit\_norms" : "true",  
> "include\_in\_parent":true,  
> "properties":{  
> "event\_type":{"type" : "string",  
> "store" : "yes", "index" :  
> "not\_analyzed", "omit\_norms" : "true"},  
> "attributes":{  
> "properties":{  
> "event\_attribute\_name":{"type" : "string",  
> "store" : "yes",  
> "index" : "not\_analyzed", "omit\_norms" : "true"},  
> "event\_attribute\_value":{"type" : "string",  
> "store" : "yes",  
> "index" : "not\_analyzed", "omit\_norms" : "true"}  
> }  
> },  
> "event\_attribute\_instance":{"type"  
> : "string", "store" : "yes",  
> "precision\_step" : "0"}  
> }  
> }
> 
> I tried indexing data using a Curl with this mapping, which worked.  
> But when I tried the same using Java API, the data was indexed  
> wrong(unreadable). I have given below the snippet of the code I  
> followed
> 
> XContentBuilder xb1 = XContentFactory.jsonBuilder().startObject();  
> XContentBuilder xb2 = XContentFactory.jsonBuilder().startObject();
> 
> xb1.startArray("eventnested");  
> for(int j=0;j\<2;j++)  
> {  
> xb2.field("event\_type",eventType);  
> xb2.field("event\_attribute\_instance",eventInstance);  
> xb2.startArray("attributes");  
> for(int i=0;i\<2;i++)  
> {  
> XContentBuilder xb3 = XContentFactory.jsonBuilder().startObject();  
> xb3.field("event\_attribute\_name", attrName);  
> xb3.field("event\_attribute\_value", attrValue);  
> xb2.value(xb3.copiedBytes());  
> }  
> xb1.value(xb2.copiedBytes());  
> }
> 
> After indexing the data, when I read the response the data of the  
> particular field looked like
> 
> "eventnested.event\_type":
> 
> ["eyJldmVudF90eXBlIjoiUXVvdGF0aW9uIiwiZXZlbnRfYXR0cmlidXRlX2luc3RhbmNlIjoiMSIsImF0dHJpYnV0ZXMiOlsiZXlKbGRtVnVkRjloZEhSeWFXSjFkR1ZmYm1GdFpTSTZJbkJsY25OdmJpQWlMQ0psZG1WdWRGOWhkSFJ5YVdKMWRHVmZkbUZzZFdVaU9pSkxZWGtnVFdGcmFIVmlaV3hoSW4wPSJdLCJhdHRyaWJ1dGVzIjpbImV5SmxkbVZ1ZEY5aGRIUnlhV0oxZEdWZmJtRnRaU0k2SW5GMWIzUmxJQ0lzSW1WMlpXNTBYMkYwZEhKcFluVjBaVjkyWVd4MVpTSTZJblJvWlNCaWIza2djbUZ3WldRZ2RHaGxJSEJoYVhJZ2IyNGdiblZ0WlhKdmRYTWdiMk5qWVhOcGIyNXpMQ0IzYVhSb0lIUm9aU0JzWVhSbGMzUWdhVzVqYVdSbGJuUWdZbVZwYm1jZ2IyNGdSbkpwWkdGNUluMD0iXX0=","eyJldmVudF90eXBlIjoiUXVvdGF0aW9uIiwiZXZlbnRfYXR0cmlidXRlX2luc3RhbmNlIjoiMSIsImF0dHJpYnV0ZXMiOlsiZXlKbGRtVnVkRjloZEhSeWFXSjFkR1ZmYm1GdFpTSTZJbkJsY25OdmJpQWlMQ0psZG1WdWRGOWhkSFJ5YVdKMWRHVmZkbUZzZFdVaU9pSkxZWGtnVFdGcmFIVmlaV3hoSW4wPSJdLCJhdHRyaWJ1dGVzIjpbImV5SmxkbVZ1ZEY5aGRIUnlhV0oxZEdWZmJtRnRaU0k2SW5GMWIzUmxJQ0lzSW1WMlpXNTBYMkYwZEhKcFluVjBaVjkyWVd4MVpTSTZJblJvWlNCMFpXVnVZV2RsY2lCb1lYTWdZbVZsYmlCd2JHRmpaV1FnYVc0Z1lTQnpZV1psZEhrZ2FHOXRaU0JoYm1RZ2QybHNiQ0JpWlNCamFHRnlaMlZrSUhkcGRHZ2djbUZ3WlNKOSJdfQ=="]}
> 
> I feel like the code is working very weird. Could anyone pls look  
> above and show me a path
> 
> Thanks in advance!  
> Regards,  
> Manoj.

---

<div class="post-metadata">

**Author:** ![manoj\_2](https://avatars.discourse-cdn.com/v4/letter/m/e0b2c6/32.png) [@manoj\_2](https://discuss.elastic.co/u/manoj_2)\
**Post date:** [April 4, 2012, 5:37pm UTC](https://discuss.elastic.co/t/array-type-inside-nested-index-unreadable-response/7225/3 "2012-04-04T17:37:49Z")

</div>

Thanks for the info Kimchy...

Still I would feel comfortable if I get this doubt cleared....

The mapping of the nested fields shows that, we are almost storing a builder object inside a field, which is what I have tried through Java

Lemme know if I have understood it wrong!!!

----- Reply message -----  
From: "Shay Banon" [kimchy@gmail.com](mailto:kimchy@gmail.com)  
Date: Wed, Apr 4, 2012 8:32 pm  
Subject: Array type inside Nested Index - unreadable response  
To: [elasticsearch@googlegroups.com](mailto:elasticsearch@googlegroups.com)

You are not building the data correctly, since you pass a binary value to  
the builder? Just use your favorite json generation library, you don't have  
to use the XContentBuilder (which actually is very similar to jackson  
generator).

On Wed, Apr 4, 2012 at 4:50 PM, Manoj [manokrrish@gmail.com](mailto:manokrrish@gmail.com) wrote:

> Hi,
> 
> I am working on a task which required to have an array of nested Index  
> for a field, the mapping of which is given below
> 
> ```
> "eventnested":{
> "type" : "nested", "store" : "yes", "index"
> 
> ```
> 
> : "analyzed",  
> "omit\_norms" : "true",  
> "include\_in\_parent":true,  
> "properties":{  
> "event\_type":{"type" : "string",  
> "store" : "yes", "index" :  
> "not\_analyzed", "omit\_norms" : "true"},  
> "attributes":{  
> "properties":{  
> "event\_attribute\_name":{"type" : "string",  
> "store" : "yes",  
> "index" : "not\_analyzed", "omit\_norms" : "true"},  
> "event\_attribute\_value":{"type" : "string",  
> "store" : "yes",  
> "index" : "not\_analyzed", "omit\_norms" : "true"}  
> }  
> },  
> "event\_attribute\_instance":{"type"  
> : "string", "store" : "yes",  
> "precision\_step" : "0"}  
> }  
> }
> 
> I tried indexing data using a Curl with this mapping, which worked.  
> But when I tried the same using Java API, the data was indexed  
> wrong(unreadable). I have given below the snippet of the code I  
> followed
> 
> XContentBuilder xb1 = XContentFactory.jsonBuilder().startObject();  
> XContentBuilder xb2 = XContentFactory.jsonBuilder().startObject();
> 
> xb1.startArray("eventnested");  
> for(int j=0;j\<2;j++)  
> {  
> xb2.field("event\_type",eventType);  
> xb2.field("event\_attribute\_instance",eventInstance);  
> xb2.startArray("attributes");  
> for(int i=0;i\<2;i++)  
> {  
> XContentBuilder xb3 = XContentFactory.jsonBuilder().startObject();  
> xb3.field("event\_attribute\_name", attrName);  
> xb3.field("event\_attribute\_value", attrValue);  
> xb2.value(xb3.copiedBytes());  
> }  
> xb1.value(xb2.copiedBytes());  
> }
> 
> After indexing the data, when I read the response the data of the  
> particular field looked like
> 
> "eventnested.event\_type":
> 
> ["eyJldmVudF90eXBlIjoiUXVvdGF0aW9uIiwiZXZlbnRfYXR0cmlidXRlX2luc3RhbmNlIjoiMSIsImF0dHJpYnV0ZXMiOlsiZXlKbGRtVnVkRjloZEhSeWFXSjFkR1ZmYm1GdFpTSTZJbkJsY25OdmJpQWlMQ0psZG1WdWRGOWhkSFJ5YVdKMWRHVmZkbUZzZFdVaU9pSkxZWGtnVFdGcmFIVmlaV3hoSW4wPSJdLCJhdHRyaWJ1dGVzIjpbImV5SmxkbVZ1ZEY5aGRIUnlhV0oxZEdWZmJtRnRaU0k2SW5GMWIzUmxJQ0lzSW1WMlpXNTBYMkYwZEhKcFluVjBaVjkyWVd4MVpTSTZJblJvWlNCaWIza2djbUZ3WldRZ2RHaGxJSEJoYVhJZ2IyNGdiblZ0WlhKdmRYTWdiMk5qWVhOcGIyNXpMQ0IzYVhSb0lIUm9aU0JzWVhSbGMzUWdhVzVqYVdSbGJuUWdZbVZwYm1jZ2IyNGdSbkpwWkdGNUluMD0iXX0=","eyJldmVudF90eXBlIjoiUXVvdGF0aW9uIiwiZXZlbnRfYXR0cmlidXRlX2luc3RhbmNlIjoiMSIsImF0dHJpYnV0ZXMiOlsiZXlKbGRtVnVkRjloZEhSeWFXSjFkR1ZmYm1GdFpTSTZJbkJsY25OdmJpQWlMQ0psZG1WdWRGOWhkSFJ5YVdKMWRHVmZkbUZzZFdVaU9pSkxZWGtnVFdGcmFIVmlaV3hoSW4wPSJdLCJhdHRyaWJ1dGVzIjpbImV5SmxkbVZ1ZEY5aGRIUnlhV0oxZEdWZmJtRnRaU0k2SW5GMWIzUmxJQ0lzSW1WMlpXNTBYMkYwZEhKcFluVjBaVjkyWVd4MVpTSTZJblJvWlNCMFpXVnVZV2RsY2lCb1lYTWdZbVZsYmlCd2JHRmpaV1FnYVc0Z1lTQnpZV1psZEhrZ2FHOXRaU0JoYm1RZ2QybHNiQ0JpWlNCamFHRnlaMlZrSUhkcGRHZ2djbUZ3WlNKOSJdfQ=="]}
> 
> I feel like the code is working very weird. Could anyone pls look  
> above and show me a path
> 
> Thanks in advance!  
> Regards,  
> Manoj.

---

<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:33am UTC](https://discuss.elastic.co/t/array-type-inside-nested-index-unreadable-response/7225/4 "2017-07-06T03:33:35Z")

</div>


