# ElasticSearch include parent source in child search

**URL:** <https://discuss.elastic.co/t/elasticsearch-include-parent-source-in-child-search/99966>\
**Category:** Elasticsearch\
**Created:** [September 10, 2017, 10:02am UTC](https://discuss.elastic.co/t/elasticsearch-include-parent-source-in-child-search/99966 "2017-09-10T10:02:08Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Marco\_Count](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/marco_count/32/21948_2.png) [@Marco\_Count](https://discuss.elastic.co/u/Marco_Count)\
**Post date:** [September 10, 2017, 10:02am UTC](https://discuss.elastic.co/t/elasticsearch-include-parent-source-in-child-search/99966/1 "2017-09-10T10:02:08Z")

</div>

I have a parent/child relationship between an user and many posts.  
I know that elasticsearch is not a relational db and there are no joins but I would like to find the best way to achieve this goal.

When I search for a post I need to provide the user who published the post alongside the post source.

One possible solution would be to denormalize user data at index time but username could change quite often and I'm not sure about using updateByQuery for string modifications ( Can the username be used for script injection?)

The second solution I was looking for is the parent/child solution but I can not find any way to include the parent in each child but sending a get request for each parent id.

---

<div class="post-metadata">

**Author:** ![spinscale](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/spinscale/32/25011_2.png) [@spinscale](https://discuss.elastic.co/u/spinscale)\
**Post date:** [September 11, 2017, 7:06am UTC](https://discuss.elastic.co/t/elasticsearch-include-parent-source-in-child-search/99966/2 "2017-09-11T07:06:52Z")

</div>

Check out [inner\_hits](https://www.elastic.co/guide/en/elasticsearch/reference/5.5/search-request-inner-hits.html), that might help you.

--Alex

---

<div class="post-metadata">

**Author:** ![Marco\_Count](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/marco_count/32/21948_2.png) [@Marco\_Count](https://discuss.elastic.co/u/Marco_Count)\
**Post date:** [September 12, 2017, 9:11am UTC](https://discuss.elastic.co/t/elasticsearch-include-parent-source-in-child-search/99966/3 "2017-09-12T09:11:30Z")

</div>

Using has\_child and inner hits I lose the score of each child if a parent has more than one child.  
What I want to achieve is a normal match query with normal scoring but I want to include in each child his parent

---

<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:** [October 10, 2017, 9:11am UTC](https://discuss.elastic.co/t/elasticsearch-include-parent-source-in-child-search/99966/4 "2017-10-10T09:11:40Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
