# Getting parent id in parent-child mapping

**URL:** <https://discuss.elastic.co/t/getting-parent-id-in-parent-child-mapping/12340>\
**Category:** Elasticsearch\
**Created:** [June 10, 2013, 4:56am UTC](https://discuss.elastic.co/t/getting-parent-id-in-parent-child-mapping/12340 "2013-06-10T04:56:40Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Chetana](https://avatars.discourse-cdn.com/v4/letter/c/dbc845/32.png) [@Chetana](https://discuss.elastic.co/u/Chetana)\
**Post date:** [June 10, 2013, 4:56am UTC](https://discuss.elastic.co/t/getting-parent-id-in-parent-child-mapping/12340/1 "2013-06-10T04:56:40Z")

</div>

I am using parent-child and the mapping is having the field \_parent and I  
set parent to actual parent id during indexing.  
But the search result returns all the fields except the parent and I also  
could not figure out any method to get the parent id.  
How should I get a parent id of the child document ?

Thanks

--  
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:** ![q42jaap](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/q42jaap/32/2241_2.png) [@q42jaap](https://discuss.elastic.co/u/q42jaap)\
**Post date:** [June 11, 2013, 9:27pm UTC](https://discuss.elastic.co/t/getting-parent-id-in-parent-child-mapping/12340/2 "2013-06-11T21:27:22Z")

</div>

Hi Chetana,

You can specify the \_parent and \_source in the fields. It will list the  
\_parent in the "fields" array in the hit, but the \_source will be at it's  
normal place in the hit.

curl 'localhost:9200/indexname/childname/\_search' -d '{  
fields:["\_parent", "\_source"]  
}'

See also:  
[http://www.elasticsearch.org/guide/reference/api/search/fields/](http://www.elasticsearch.org/guide/reference/api/search/fields/)

Jaap

--  
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:31am UTC](https://discuss.elastic.co/t/getting-parent-id-in-parent-child-mapping/12340/3 "2017-07-06T02:31:44Z")

</div>


