# Get \_parent source fields from child document

**URL:** <https://discuss.elastic.co/t/get--parent-source-fields-from-child-document/55707>\
**Category:** Elasticsearch\
**Created:** [July 17, 2016, 10:27pm UTC](https://discuss.elastic.co/t/get--parent-source-fields-from-child-document/55707 "2016-07-17T22:27:31Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Sergey\_Bevzuk](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/sergey_bevzuk/32/10926_2.png) [@Sergey\_Bevzuk](https://discuss.elastic.co/u/Sergey_Bevzuk)\
**Post date:** [July 17, 2016, 10:27pm UTC](https://discuss.elastic.co/t/get--parent-source-fields-from-child-document/55707/1 "2016-07-17T22:27:31Z")

</div>

Hi all,

actually here is my question:

> <https://stackoverflow.com/questions/38426268/elasticsearch-get-parent-source-fields-from-child-document>

  
Maybe some of you have some ideas how to do it.

---

<div class="post-metadata">

**Author:** ![mvg](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/mvg/32/98890_2.png) [@mvg](https://discuss.elastic.co/u/mvg)\
**Post date:** [July 18, 2016, 9:34am UTC](https://discuss.elastic.co/t/get--parent-source-fields-from-child-document/55707/2 "2016-07-18T09:34:58Z")

</div>

> $reqParams['body'] = array(  
> 'query' =\> array(  
> 'has\_parent' =\> [  
> 'parent\_type' =\> 'user',  
> 'query' =\> [  
> 'match\_all' =\>   
> ],  
> 'inner\_hits' =\> [  
> '\_source' =\> ['\*']  
> ]  
> ],  
> )  
> );

I think this query from your question on SO is the right direction. I don't fully understand your question, but you do two kinds of filtering on both parent and child side.

You can either do filter by query. You add a query inside the `has_parent`'s inner query instead of the `match_all` query to filter by properties on the parent side. Or build a `bool` query, add the `has_parent` query as must clause and then define another must query with a query to filter on the child side.

Source filtering can be applied on the parent side (modifying the `_source` filtering inside the `inner_hits` element) or child side (adding a `_source` filtering as top level element to the search request).

---

<div class="post-metadata">

**Author:** ![Sergey\_Bevzuk](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/sergey_bevzuk/32/10926_2.png) [@Sergey\_Bevzuk](https://discuss.elastic.co/u/Sergey_Bevzuk)\
**Post date:** [July 18, 2016, 10:04am UTC](https://discuss.elastic.co/t/get--parent-source-fields-from-child-document/55707/3 "2016-07-18T10:04:35Z")

</div>

Thank YOU!

This is what I did and it works

> **[Screenshot "pngbay - \[D\_\_Projects\_PngbayProject\_web\_pngbay\] - \[pngbay\] -...](https://monosnap.com/file/X5fvAnuJUUm95tL0dRYDMObUVcH1bf)**
>
> Click to see the full size picture

---

<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, 10:34pm UTC](https://discuss.elastic.co/t/get--parent-source-fields-from-child-document/55707/4 "2017-07-05T22:34:46Z")

</div>


