# Nested object retrieval (not querying, not filtering, just yet)

**URL:** <https://discuss.elastic.co/t/nested-object-retrieval-not-querying-not-filtering-just-yet/14369>\
**Category:** Elasticsearch\
**Created:** [November 12, 2013, 8:37pm UTC](https://discuss.elastic.co/t/nested-object-retrieval-not-querying-not-filtering-just-yet/14369 "2013-11-12T20:37:44Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Vladimir\_Khazin](https://avatars.discourse-cdn.com/v4/letter/v/258eb7/32.png) [@Vladimir\_Khazin](https://discuss.elastic.co/u/Vladimir_Khazin)\
**Post date:** [November 12, 2013, 8:37pm UTC](https://discuss.elastic.co/t/nested-object-retrieval-not-querying-not-filtering-just-yet/14369/1 "2013-11-12T20:37:44Z")

</div>

I am trying to figure out how to retrieve data from nested objects as if it  
was a separate index/type.  
According to documentation ES index the nested docs separately, but how do  
I retrieve it.

My data is coming in as deeply nested and rich document, I have simplified  
it to bare minimum to get to the point:

_Sample data:_  
{  
"AssetId": "4b7b5c27-7cdd-40f0-bc01-24186bc108cd",  
"AssetTitle": "Inside Llewyn Davis",  
"CastMembers": [  
{  
"AssetCastCrewMemberId": "6765678",  
"CastCrewName": "Oscar Isaac",  
"CastCrewRole": "Actor",  
},  
{  
"AssetCastCrewMemberId": "15514452",  
"CastCrewName": "Carey Mulligan",  
"CastCrewRole": "Actor",  
}  
]  
}

_Desired output:_  
{  
"took": 6,  
"timed\_out": false,  
"\_shards": {  
"total": 5,  
"successful": 5,  
"failed": 0  
},  
"hits": {  
"total": 2,  
"max\_score": 2.2038321,  
"hits": [  
{  
"\_index": "metadata",  
"\_type": "asset",  
"\_id": "6765678",  
"\_score": 2.2038321,  
"\_source": {  
"AssetCastCrewMemberId": "6765678",  
"CastCrewName": "Oscar Isaac",  
"CastCrewRole": "Actor-1",  
}  
},  
{  
"\_index": "metadata",  
"\_type": "asset",  
"\_id": "15514452",  
"\_score": 2.2038321,  
"\_source": {  
"AssetCastCrewMemberId": "15514452",  
"CastCrewName": "Carey Mulligan",  
"CastCrewRole": "Actor-2",  
}  
},  
]  
}

_When I tried fields selection:_  
{  
"fields": [  
"CastMembers.AssetCastCrewMemberId",  
"CastMembers.CastCrewName",  
"CastMembers.CastCrewRole"  
]  
}

_I got:_  
{  
"took": 9,  
"timed\_out": false,  
"\_shards": {  
"total": 5,  
"successful": 5,  
"failed": 0  
},  
"hits": {  
"total": 1,  
"max\_score": 1,  
"hits": [  
{  
"\_index": "metadata",  
"\_type": "asset",  
"\_id": "4b7b5c27-7cdd-40f0-bc01-24186bc108cd",  
"\_score": 1,  
"fields": {  
"CastMembers.CastCrewName": [  
"Oscar Isaac",  
"Carey Mulligan",  
],  
"CastMembers.CastCrewRole": [  
"Actor-1",  
"Actor-2",  
],  
"CastMembers.AssetCastCrewMemberId": [  
"6765678",  
"15514452",  
]  
}  
}  
]  
}  
}

Quite not the way I need it as association between Oscar Isaac and his role  
Actor-1 is his is is not reliable.

Advice or even ideas are greatly appreciated.

--  
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:** [November 12, 2013, 8:49pm UTC](https://discuss.elastic.co/t/nested-object-retrieval-not-querying-not-filtering-just-yet/14369/2 "2013-11-12T20:49:12Z")

</div>

First of all, it appears that you are not using nested objects, but inner  
objects. This article will hopefully help understanding the difference:

> **[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.

True nested documents (or perhaps parent/child) appear to be what you are  
looking for. Keep in mind, with nested documents, your queries will return  
the correct top-level document, but all the nested children will be  
returned as well. [Return matching nested inner objects per hit · Issue #3022 · elastic/elasticsearch · GitHub](https://github.com/elasticsearch/elasticsearch/issues/3022)

Cheers,

Ivan

On Tue, Nov 12, 2013 at 12:37 PM, Vladimir Khazin \<  
vladimir.khazin@icssolutions.ca\> wrote:

> I am trying to figure out how to retrieve data from nested objects as if  
> it was a separate index/type.  
> According to documentation ES index the nested docs separately, but how do  
> I retrieve it.
> 
> My data is coming in as deeply nested and rich document, I have simplified  
> it to bare minimum to get to the point:
> 
> _Sample data:_  
> {  
> "AssetId": "4b7b5c27-7cdd-40f0-bc01-24186bc108cd",  
> "AssetTitle": "Inside Llewyn Davis",  
> "CastMembers": [  
> {  
> "AssetCastCrewMemberId": "6765678",  
> "CastCrewName": "Oscar Isaac",  
> "CastCrewRole": "Actor",  
> },  
> {  
> "AssetCastCrewMemberId": "15514452",  
> "CastCrewName": "Carey Mulligan",  
> "CastCrewRole": "Actor",  
> }  
> ]  
> }
> 
> _Desired output:_  
> {  
> "took": 6,  
> "timed\_out": false,  
> "\_shards": {  
> "total": 5,  
> "successful": 5,  
> "failed": 0  
> },  
> "hits": {  
> "total": 2,  
> "max\_score": 2.2038321,  
> "hits": [  
> {  
> "\_index": "metadata",  
> "\_type": "asset",  
> "\_id": "6765678",  
> "\_score": 2.2038321,  
> "\_source": {  
> "AssetCastCrewMemberId": "6765678",  
> "CastCrewName": "Oscar Isaac",  
> "CastCrewRole": "Actor-1",  
> }  
> },  
> {  
> "\_index": "metadata",  
> "\_type": "asset",  
> "\_id": "15514452",  
> "\_score": 2.2038321,  
> "\_source": {  
> "AssetCastCrewMemberId": "15514452",  
> "CastCrewName": "Carey Mulligan",  
> "CastCrewRole": "Actor-2",  
> }  
> },  
> ]  
> }
> 
> _When I tried fields selection:_  
> {  
> "fields": [  
> "CastMembers.AssetCastCrewMemberId",  
> "CastMembers.CastCrewName",  
> "CastMembers.CastCrewRole"  
> ]  
> }
> 
> _I got:_  
> {  
> "took": 9,  
> "timed\_out": false,  
> "\_shards": {  
> "total": 5,  
> "successful": 5,  
> "failed": 0  
> },  
> "hits": {  
> "total": 1,  
> "max\_score": 1,  
> "hits": [  
> {  
> "\_index": "metadata",  
> "\_type": "asset",  
> "\_id": "4b7b5c27-7cdd-40f0-bc01-24186bc108cd",  
> "\_score": 1,  
> "fields": {  
> "CastMembers.CastCrewName": [  
> "Oscar Isaac",  
> "Carey Mulligan",  
> ],  
> "CastMembers.CastCrewRole": [  
> "Actor-1",  
> "Actor-2",  
> ],  
> "CastMembers.AssetCastCrewMemberId": [  
> "6765678",  
> "15514452",  
> ]  
> }  
> }  
> ]  
> }  
> }
> 
> Quite not the way I need it as association between Oscar Isaac and his  
> role Actor-1 is his is is not reliable.
> 
> Advice or even ideas are greatly appreciated.
> 
> --  
> 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:** ![Vladimir\_Khazin](https://avatars.discourse-cdn.com/v4/letter/v/258eb7/32.png) [@Vladimir\_Khazin](https://discuss.elastic.co/u/Vladimir_Khazin)\
**Post date:** [November 13, 2013, 6:09pm UTC](https://discuss.elastic.co/t/nested-object-retrieval-not-querying-not-filtering-just-yet/14369/3 "2013-11-13T18:09:45Z")

</div>

Thank you, Ivan, for the comment!

After reading the difference between inner, nested, and parent/child  
mapping it seems to me that there is no (practical) way to achieve the  
desired query output.  
Other than creating parent/child mapping between asset and actor and  
indexing actors separately from assets.

Is there any better alternative to the direction I am about to take:

1. Index asset as one type
2. Index actor as another type completely disconnected from the asset  
and handle the sync by means outside of elastic search

Is there any equivalent to map reduce, triggers, or couchbase view  
implementation in elastic search to reshape the data - not just to  
map/remap the data?

--  
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:07am UTC](https://discuss.elastic.co/t/nested-object-retrieval-not-querying-not-filtering-just-yet/14369/4 "2017-07-06T02:07:28Z")

</div>


