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?