For example, I have an index with following mapping:
{
"mappings": {
"docs": {
"properties": {
"QueryClicks": {
"type": "nested",
"properties": {
"Count": {
"type": "long"
},
"Term": {
"type": "string",
"fields": {
"lowercaseraw": {
"type": "string",
"analyzer": "lowercase_keyword"
}
}
}
}
},
"Title": {
"type": "string"
}
}
}
}
}
And example document:
{
"Title": "The Heart of the Elastic Stack"
"QueryClicks": [
{ "Term": "elastic stack", "Count": 100},
{ "Term": "elastic", "Count": 50},
{ "Term": "hard of the elastic", "Count": 200},
]
}
Now I want to get all documents which match query terms in Title field, and boost the score by QueryClicks.Count if the query term exactly match the corresponding QueryClicks.Term field.
Following is my initial 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 socre 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"
Is it possible?
Or any other approach to solve my requirement?