# Parent-Child mapping has\_child query score mode issue/query

**URL:** <https://discuss.elastic.co/t/parent-child-mapping-has-child-query-score-mode-issue-query/87047>\
**Category:** Elasticsearch\
**Created:** [May 24, 2017, 9:23pm UTC](https://discuss.elastic.co/t/parent-child-mapping-has-child-query-score-mode-issue-query/87047 "2017-05-24T21:23:34Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Atul\_Bagga](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/atul_bagga/32/15047_2.png) [@Atul\_Bagga](https://discuss.elastic.co/u/Atul_Bagga)\
**Post date:** [May 24, 2017, 9:23pm UTC](https://discuss.elastic.co/t/parent-child-mapping-has-child-query-score-mode-issue-query/87047/1 "2017-05-24T21:23:34Z")

</div>

I have parent child mapping used for my documents. Given a search text I need to search across parent and child document fields and get results in parent child nested form where any matches in the child document fields should boost relevance of the resultant parent doc.

I am using query something like this..

**..Upper level should query for text1 and text2**  
"query": {  
"bool": {  
"minimum\_number\_should\_match": 1,  
"should": [  
{

**..inner should query 1 for text1**  
"query": {  
"bool": {  
"minimum\_number\_should\_match": 1,  
"should": [  
{  
"multi\_match": { **//..parent field match**  
"query": " **searchtext1**",  
"fields": [  
"parentField1",  
"parentField2"  
]  
}  
},  
{  
"has\_child": { **//..has child text1**  
"score\_mode": " **sum**",  
"type": "ChildDocument",  
"query": {  
"multi\_match": {  
"query": " **searchtext1**",  
"fields": [  
"ChildField1",  
"ChildField2"  
]  
}  
},  
"inner\_hits" : {  
"size": 2,  
"name": " **InnerHits1**"  
}  
}  
}],

**//..inner should query 2 for text2**  
"query": {  
"bool": {  
"minimum\_number\_should\_match": 1,  
"should": [  
{  
"multi\_match": { **//..parent field match for text2**  
"query": " **searchtext2**",  
"fields": [  
"parentField1",  
"parentField2"  
]  
}  
},  
{  
"has\_child": { **//..has child for text2**  
"score\_mode": " **sum**",  
"type": "ChildDocument",  
"query": {  
"multi\_match": {  
"query": " **searchtext2**",  
"fields": [  
"ChildField1",  
"ChildField2"  
]  
}  
},  
"inner\_hits" : {  
"size": 2,  
"name": " **InnerHits2**"  
}  
}  
}]

**//..closing outer bool should query**  
}}}

Now my result will be something like this if searchtext1 and searchtext2 both get a match in same child document - ChildDocument1.

**Result**  
ParentDocument1 (Score-X)  
-InnerHits1 - ChildDocument1 - Score-Y  
-InnerHits2 - ChildDocument1 - Score-Z, ChildDocument2- Score-W  
ParentDocument2 (Score --)  
..  
..

**Question:** Since I used score mode as sum but there are multiple inner hits with some common repository in multiple hits also. I am curious on how is the score X calculated for the ParentDocument1 above?

---

<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:** [June 21, 2017, 9:23pm UTC](https://discuss.elastic.co/t/parent-child-mapping-has-child-query-score-mode-issue-query/87047/2 "2017-06-21T21:23:42Z")

</div>

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