# Read nested documents not as expected

**URL:** <https://discuss.elastic.co/t/read-nested-documents-not-as-expected/12663>\
**Category:** Elasticsearch\
**Created:** [July 4, 2013, 11:17am UTC](https://discuss.elastic.co/t/read-nested-documents-not-as-expected/12663 "2013-07-04T11:17:45Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Halit\_Cimen](https://avatars.discourse-cdn.com/v4/letter/h/d6d6ee/32.png) [@Halit\_Cimen](https://discuss.elastic.co/u/Halit_Cimen)\
**Post date:** [July 4, 2013, 11:17am UTC](https://discuss.elastic.co/t/read-nested-documents-not-as-expected/12663/1 "2013-07-04T11:17:45Z")

</div>

Hi,

we have a problem to read nested documents (example here localized\_data),  
which we mapped as follows.

mapping :  
{  
"generic": { "\_id": { "path": "id" },  
"\_source" : { "enabled" : false },  
"properties": {  
"p\_id": { "type": "long", "store": "yes" },  
"p\_type\_id": { "type": "long", "store": "yes" },  
"localized\_data": {  
"type": "nested",  
"include\_in\_root" : "true",  
"properties": {  
"l\_id": { "type": "string", "store": "yes" },  
"title": { "type": "string", "store": "yes" },  
"description": { "type": "string", "store": "yes" },  
"artists": { "type": "string", "store": "yes" }  
}  
}  
}  
}  
}

is there any way to read the nested documents as related objects  
e.g.:  
first nested document:

localized\_data.l\_id = "1" ,

localized\_data.title = "test1"

localized\_data.description = "desc1

localized\_data.artists = "artiist1"

second nested document:

localized\_data.l\_id = "2" ,

localized\_data.title = "test2"

localized\_data.description = "desc2

localized\_data.artists = "artiist2"

actually we get the values as arrays

localized\_data.l\_id = [1,2], localized\_data.title = [test1,test2],  
localized\_data.description = [desc1,desc2], localized\_data.artists =  
[artiist1,artiist2]

we cannot assign the l\_id to the title from the result, because we get  
separated arrays for each field.  
is there a way to get the nested information for each nested document  
separately?  
we make a matchAll query, no nested search query.

suggestions?

thx  
halit

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

**Author:** ![Ivan](https://avatars.discourse-cdn.com/v4/letter/i/df788c/32.png) [@Ivan](https://discuss.elastic.co/u/Ivan)\
**Post date:** [July 5, 2013, 3:16pm UTC](https://discuss.elastic.co/t/read-nested-documents-not-as-expected/12663/2 "2013-07-05T15:16:07Z")

</div>

I never worked with source disabled and nested documents, but can you store  
the localized\_data field? That should return an array of objects.

--  
Ivan

On Thu, Jul 4, 2013 at 4:17 AM, Halit Cimen [halit.cimen@gmail.com](mailto:halit.cimen@gmail.com) wrote:

> Hi,
> 
> we have a problem to read nested documents (example here localized\_data),  
> which we mapped as follows.
> 
> mapping :  
> {  
> "generic": { "\_id": { "path": "id" },  
> "\_source" : { "enabled" : false },  
> "properties": {  
> "p\_id": { "type": "long", "store": "yes" },  
> "p\_type\_id": { "type": "long", "store": "yes" },  
> "localized\_data": {  
> "type": "nested",  
> "include\_in\_root" : "true",  
> "properties": {  
> "l\_id": { "type": "string", "store": "yes" },  
> "title": { "type": "string", "store": "yes" },  
> "description": { "type": "string", "store": "yes" },  
> "artists": { "type": "string", "store": "yes" }  
> }  
> }  
> }  
> }  
> }
> 
> is there any way to read the nested documents as related objects  
> e.g.:  
> first nested document:
> 
> localized\_data.l\_id = "1" ,
> 
> localized\_data.title = "test1"
> 
> localized\_data.description = "desc1
> 
> localized\_data.artists = "artiist1"
> 
> second nested document:
> 
> localized\_data.l\_id = "2" ,
> 
> localized\_data.title = "test2"
> 
> localized\_data.description = "desc2
> 
> localized\_data.artists = "artiist2"
> 
> actually we get the values as arrays
> 
> localized\_data.l\_id = [1,2], localized\_data.title = [test1,test2],  
> localized\_data.description = [desc1,desc2], localized\_data.artists =  
> [artiist1,artiist2]
> 
> we cannot assign the l\_id to the title from the result, because we get  
> separated arrays for each field.  
> is there a way to get the nested information for each nested document  
> separately?  
> we make a matchAll query, no nested search query.
> 
> suggestions?
> 
> thx  
> halit
> 
> --  
> You received this message because you are subscribed to the Google Groups  
> "elasticsearch" group.  
> To unsubscribe from this group and stop receiving emails from it, send an  
> email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
> For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

**Author:** ![Halit\_Cimen](https://avatars.discourse-cdn.com/v4/letter/h/d6d6ee/32.png) [@Halit\_Cimen](https://discuss.elastic.co/u/Halit_Cimen)\
**Post date:** [July 5, 2013, 3:51pm UTC](https://discuss.elastic.co/t/read-nested-documents-not-as-expected/12663/3 "2013-07-05T15:51:55Z")

</div>

yes, we can store the localized\_data field,  
but we disabled the \_source field, because it is not indexed (searchable,  
just stored). (as described here  
[Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/reference/mapping/source-field/))  
it is only overhead, that we do not want

> ... That should return an array of objects.

unfortunately, it not returns an array of object.

if we make a search request with :

```
   String[] field = new String[] {"*"};
   QueryBuilder qb = QueryBuilders.matchQuery(p_ID,"2282104");
           SearchResponse response = 

```

node.client().prepareSearch("index\_name")  
.setSearchType(SearchType.DEFAULT) .setQuery(qb)  
.addFields( field) .setSize(1000).execute().actionGet();

SearchHit  
csb\_dc\_list - [182:12, 182:13]  
p\_id - [2282104]  
localized\_data.title - [Tre Amiche, 3 Gatas quentes, 3 Hot Girls, 3 heiße  
Mädels]  
p\_type\_id - [9]  
localized\_data.locale\_id - [292, 433, 0, 290]

as you see the fields of localized\_data are returned as arrays.  
but we want get an array of localized\_data objects.

Am Freitag, 5. Juli 2013 17:16:07 UTC+2 schrieb Ivan Brusic:

> I never worked with source disabled and nested documents, but can you  
> store the localized\_data field? That should return an array of objects.
> 
> --  
> Ivan
> 
> On Thu, Jul 4, 2013 at 4:17 AM, Halit Cimen \<[halit...@gmail.com](mailto:halit...@gmail.com)\<javascript:\>
> 
> > wrote:
> 
> > Hi,
> > 
> > we have a problem to read nested documents (example here localized\_data),  
> > which we mapped as follows.
> > 
> > mapping :  
> > {  
> > "generic": { "\_id": { "path": "id" },  
> > "\_source" : { "enabled" : false },  
> > "properties": {  
> > "p\_id": { "type": "long", "store": "yes" },  
> > "p\_type\_id": { "type": "long", "store": "yes" },  
> > "localized\_data": {  
> > "type": "nested",  
> > "include\_in\_root" : "true",  
> > "properties": {  
> > "l\_id": { "type": "string", "store": "yes" },  
> > "title": { "type": "string", "store": "yes" },  
> > "description": { "type": "string", "store": "yes" },  
> > "artists": { "type": "string", "store": "yes" }  
> > }  
> > }  
> > }  
> > }  
> > }
> > 
> > is there any way to read the nested documents as related objects  
> > e.g.:  
> > first nested document:
> > 
> > localized\_data.l\_id = "1" ,
> > 
> > localized\_data.title = "test1"
> > 
> > localized\_data.description = "desc1
> > 
> > localized\_data.artists = "artiist1"
> > 
> > second nested document:
> > 
> > localized\_data.l\_id = "2" ,
> > 
> > localized\_data.title = "test2"
> > 
> > localized\_data.description = "desc2
> > 
> > localized\_data.artists = "artiist2"
> > 
> > actually we get the values as arrays
> > 
> > localized\_data.l\_id = [1,2], localized\_data.title = [test1,test2],  
> > localized\_data.description = [desc1,desc2], localized\_data.artists =  
> > [artiist1,artiist2]
> > 
> > we cannot assign the l\_id to the title from the result, because we get  
> > separated arrays for each field.  
> > is there a way to get the nested information for each nested document  
> > separately?  
> > we make a matchAll query, no nested search query.
> > 
> > suggestions?
> > 
> > thx  
> > halit
> > 
> > --  
> > You received this message because you are subscribed to the Google Groups  
> > "elasticsearch" group.  
> > To unsubscribe from this group and stop receiving emails from it, send an  
> > email to [elasticsearc...@googlegroups.com](mailto:elasticsearc...@googlegroups.com) \<javascript:\>.  
> > For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

**Author:** ![Ivan](https://avatars.discourse-cdn.com/v4/letter/i/df788c/32.png) [@Ivan](https://discuss.elastic.co/u/Ivan)\
**Post date:** [July 5, 2013, 4:36pm UTC](https://discuss.elastic.co/t/read-nested-documents-not-as-expected/12663/4 "2013-07-05T16:36:51Z")

</div>

Is the above example with localized\_data stored or with the original  
mapping?

And enabling source is only an overhead in index size. If you are  
retrieving several fields, then retrieving from source can/should be faster  
since you are not executing an index lookup for each individual field.

--  
Ivan

On Fri, Jul 5, 2013 at 8:51 AM, Halit Cimen [halit.cimen@gmail.com](mailto:halit.cimen@gmail.com) wrote:

> yes, we can store the localized\_data field,  
> but we disabled the \_source field, because it is not indexed (searchable,  
> just stored). (as described here  
> [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/reference/mapping/source-field/))  
> it is only overhead, that we do not want
> 
> > ... That should return an array of objects.
> 
> unfortunately, it not returns an array of object.
> 
> if we make a search request with :
> 
> ```
> String[] field = new String[] {"*"};
> QueryBuilder qb = QueryBuilders.matchQuery(p_ID,"2282104");
> SearchResponse response =
> 
> ```
> 
> node.client().prepareSearch("index\_name")  
> .setSearchType(SearchType.DEFAULT) .setQuery(qb)  
> .addFields( field) .setSize(1000).execute().actionGet();
> 
> SearchHit  
> csb\_dc\_list - [182:12, 182:13]  
> p\_id - [2282104]  
> localized\_data.title - [Tre Amiche, 3 Gatas quentes, 3 Hot Girls, 3 heiße  
> Mädels]  
> p\_type\_id - [9]  
> localized\_data.locale\_id - [292, 433, 0, 290]
> 
> as you see the fields of localized\_data are returned as arrays.  
> but we want get an array of localized\_data objects.
> 
> Am Freitag, 5. Juli 2013 17:16:07 UTC+2 schrieb Ivan Brusic:
> 
> > I never worked with source disabled and nested documents, but can you  
> > store the localized\_data field? That should return an array of objects.
> > 
> > --  
> > Ivan
> > 
> > On Thu, Jul 4, 2013 at 4:17 AM, Halit Cimen [halit...@gmail.com](mailto:halit...@gmail.com) wrote:
> > 
> > > Hi,
> > > 
> > > we have a problem to read nested documents (example here  
> > > localized\_data), which we mapped as follows.
> > > 
> > > mapping :  
> > > {  
> > > "generic": { "\_id": { "path": "id" },  
> > > "\_source" : { "enabled" : false },  
> > > "properties": {  
> > > "p\_id": { "type": "long", "store": "yes" },  
> > > "p\_type\_id": { "type": "long", "store": "yes" },  
> > > "localized\_data": {  
> > > "type": "nested",  
> > > "include\_in\_root" : "true",  
> > > "properties": {  
> > > "l\_id": { "type": "string", "store": "yes" },  
> > > "title": { "type": "string", "store": "yes" },  
> > > "description": { "type": "string", "store": "yes" },  
> > > "artists": { "type": "string", "store": "yes" }  
> > > }  
> > > }  
> > > }  
> > > }  
> > > }
> > > 
> > > is there any way to read the nested documents as related objects  
> > > e.g.:  
> > > first nested document:
> > > 
> > > localized\_data.l\_id = "1" ,
> > > 
> > > localized\_data.title = "test1"
> > > 
> > > localized\_data.description = "desc1
> > > 
> > > localized\_data.artists = "artiist1"
> > > 
> > > second nested document:
> > > 
> > > localized\_data.l\_id = "2" ,
> > > 
> > > localized\_data.title = "test2"
> > > 
> > > localized\_data.description = "desc2
> > > 
> > > localized\_data.artists = "artiist2"
> > > 
> > > actually we get the values as arrays
> > > 
> > > localized\_data.l\_id = [1,2], localized\_data.title = [test1,test2],  
> > > localized\_data.description = [desc1,desc2], localized\_data.artists =  
> > > [artiist1,artiist2]
> > > 
> > > we cannot assign the l\_id to the title from the result, because we get  
> > > separated arrays for each field.  
> > > is there a way to get the nested information for each nested document  
> > > separately?  
> > > we make a matchAll query, no nested search query.
> > > 
> > > suggestions?
> > > 
> > > thx  
> > > halit
> > > 
> > > --  
> > > You received this message because you are subscribed to the Google  
> > > Groups "elasticsearch" group.  
> > > To unsubscribe from this group and stop receiving emails from it, send  
> > > an email to elasticsearc...@\*\*[googlegroups.com](http://googlegroups.com).
> > > 
> > > For more options, visit [https://groups.google.com/\*\*groups/opt\_out](https://groups.google.com/**groups/opt_out)[https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out)  
> > > .
> > 
> > --  
> > You received this message because you are subscribed to the Google Groups  
> > "elasticsearch" group.  
> > To unsubscribe from this group and stop receiving emails from it, send an  
> > email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
> > For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

**Author:** ![Halit\_Cimen](https://avatars.discourse-cdn.com/v4/letter/h/d6d6ee/32.png) [@Halit\_Cimen](https://discuss.elastic.co/u/Halit_Cimen)\
**Post date:** [July 5, 2013, 4:48pm UTC](https://discuss.elastic.co/t/read-nested-documents-not-as-expected/12663/5 "2013-07-05T16:48:55Z")

</div>

localized\_data is stored.  
is there no way to get the the object array with disabled source?

Am Freitag, 5. Juli 2013 18:36:51 UTC+2 schrieb Ivan Brusic:

> Is the above example with localized\_data stored or with the original  
> mapping?
> 
> And enabling source is only an overhead in index size. If you are  
> retrieving several fields, then retrieving from source can/should be faster  
> since you are not executing an index lookup for each individual field.
> 
> --  
> Ivan
> 
> On Fri, Jul 5, 2013 at 8:51 AM, Halit Cimen \<[halit...@gmail.com](mailto:halit...@gmail.com)\<javascript:\>
> 
> > wrote:
> 
> > yes, we can store the localized\_data field,  
> > but we disabled the \_source field, because it is not indexed (searchable,  
> > just stored). (as described here  
> > [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/reference/mapping/source-field/))  
> > it is only overhead, that we do not want
> > 
> > > ... That should return an array of objects.
> > 
> > unfortunately, it not returns an array of object.
> > 
> > if we make a search request with :
> > 
> > ```
> > String[] field = new String[] {"*"};
> > QueryBuilder qb = QueryBuilders.matchQuery(p_ID,"2282104");
> > SearchResponse response = 
> > 
> > ```
> > 
> > node.client().prepareSearch("index\_name")  
> > .setSearchType(SearchType.DEFAULT) .setQuery(qb)  
> > .addFields( field) .setSize(1000).execute().actionGet();
> > 
> > SearchHit  
> > csb\_dc\_list - [182:12, 182:13]  
> > p\_id - [2282104]  
> > localized\_data.title - [Tre Amiche, 3 Gatas quentes, 3 Hot Girls, 3 heiße  
> > Mädels]  
> > p\_type\_id - [9]  
> > localized\_data.locale\_id - [292, 433, 0, 290]
> > 
> > as you see the fields of localized\_data are returned as arrays.  
> > but we want get an array of localized\_data objects.
> > 
> > Am Freitag, 5. Juli 2013 17:16:07 UTC+2 schrieb Ivan Brusic:
> > 
> > > I never worked with source disabled and nested documents, but can you  
> > > store the localized\_data field? That should return an array of objects.
> > > 
> > > --  
> > > Ivan
> > > 
> > > On Thu, Jul 4, 2013 at 4:17 AM, Halit Cimen [halit...@gmail.com](mailto:halit...@gmail.com) wrote:
> > > 
> > > > Hi,
> > > > 
> > > > we have a problem to read nested documents (example here  
> > > > localized\_data), which we mapped as follows.
> > > > 
> > > > mapping :  
> > > > {  
> > > > "generic": { "\_id": { "path": "id" },  
> > > > "\_source" : { "enabled" : false },  
> > > > "properties": {  
> > > > "p\_id": { "type": "long", "store": "yes" },  
> > > > "p\_type\_id": { "type": "long", "store": "yes" },  
> > > > "localized\_data": {  
> > > > "type": "nested",  
> > > > "include\_in\_root" : "true",  
> > > > "properties": {  
> > > > "l\_id": { "type": "string", "store": "yes" },  
> > > > "title": { "type": "string", "store": "yes" },  
> > > > "description": { "type": "string", "store": "yes" },  
> > > > "artists": { "type": "string", "store": "yes" }  
> > > > }  
> > > > }  
> > > > }  
> > > > }  
> > > > }
> > > > 
> > > > is there any way to read the nested documents as related objects  
> > > > e.g.:  
> > > > first nested document:
> > > > 
> > > > localized\_data.l\_id = "1" ,
> > > > 
> > > > localized\_data.title = "test1"
> > > > 
> > > > localized\_data.description = "desc1
> > > > 
> > > > localized\_data.artists = "artiist1"
> > > > 
> > > > second nested document:
> > > > 
> > > > localized\_data.l\_id = "2" ,
> > > > 
> > > > localized\_data.title = "test2"
> > > > 
> > > > localized\_data.description = "desc2
> > > > 
> > > > localized\_data.artists = "artiist2"
> > > > 
> > > > actually we get the values as arrays
> > > > 
> > > > localized\_data.l\_id = [1,2], localized\_data.title = [test1,test2],  
> > > > localized\_data.description = [desc1,desc2], localized\_data.artists =  
> > > > [artiist1,artiist2]
> > > > 
> > > > we cannot assign the l\_id to the title from the result, because we get  
> > > > separated arrays for each field.  
> > > > is there a way to get the nested information for each nested document  
> > > > separately?  
> > > > we make a matchAll query, no nested search query.
> > > > 
> > > > suggestions?
> > > > 
> > > > thx  
> > > > halit
> > > > 
> > > > --  
> > > > You received this message because you are subscribed to the Google  
> > > > Groups "elasticsearch" group.  
> > > > To unsubscribe from this group and stop receiving emails from it, send  
> > > > an email to elasticsearc...@\*\*[googlegroups.com](http://googlegroups.com).
> > > > 
> > > > For more options, visit [https://groups.google.com/\*\*groups/opt\_out](https://groups.google.com/**groups/opt_out)[https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out)  
> > > > .
> > > 
> > > --  
> > > You received this message because you are subscribed to the Google Groups  
> > > "elasticsearch" group.  
> > > To unsubscribe from this group and stop receiving emails from it, send an  
> > > email to [elasticsearc...@googlegroups.com](mailto:elasticsearc...@googlegroups.com) \<javascript:\>.  
> > > For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<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, 2:27am UTC](https://discuss.elastic.co/t/read-nested-documents-not-as-expected/12663/6 "2017-07-06T02:27:57Z")

</div>


