What I want is to get all documents which match query terms in Title field, and boost the score by value of a field in nested object if the query term also exactly match that nested field.
Following is my example doc:
{
"Title": "The Heart of the Elastic Stack"
"QueryClicks": [
{ "Term": "elastic stack", "Count": 100},
{ "Term": "elastic", "Count": 50},
{ "Term": "hard of the elastic", "Count": 200},
]
}
And example query DSL:
{
"query" : {
"bool" : {
"must" : [{
"match" : {
"Title" : "elastic stack"
}
}
],
"should" : [{
"nested" : {
"path" : "QueryClicks",
"query" : {
"function_score" : {
"query" : {
"match" : {
"QueryClicks.Term.lowercaseraw" : "elastic stack"
}
},
"functions" : [{
"script_score" : {
"script" : "log(doc['QueryClicks.Count'].value*4)"
}
}
],
"boost_mode" : "replace"
}
}
}
}
]
}
}
}
It somehow works, for certain queryterm, if it match one of the QueryClicks.Term, extra scores will be added to the whole score of the document.
But not perfect, what I want is to multiply the nested function score (that is, log(doc['QueryClicks.Count'].value*4) ) with the parent document's score which calculated in must clause.
If I can get the parent doc's score, then I can do something like this:
"script": "log(doc['QueryClicks.Count'].value*4) * _parent_score"
But since ES does not support getting parent score from nested query yet. Any other approaches?
The purpose is, multiply the _score which calculated by QueryClicks.Count and the _score from must query clause.