Reputation: 185
I have a document with less _score which is not retrieved at the query time when i give size:100. I need to make the document available in top 25 results. How to achieve this ? Is there any option to increase the _score manually ?
Upvotes: 1
Views: 1597
Reputation: 9320
I will describe one of the possible ways to do the trick
You could use function_score to boost the score based on some functions:
The function_score query provides several types of score functions.
script_score
weight
random_score
field_value_factor
decay functions: gauss, linear, exp
Example, that will use the field_value_factor to boost the score by multiplying the score:
{
"query": {
"function_score": {
"query": {
"match_all": {}
},
"script_score": {
"script": "_score * doc['popularity'].value"
},
"boost_mode": "multiply"
}
}
}
To enable this dynamic scoring you need to alter your yml config file with lines depending on the version of Elastic:
It's either (at least it's the way for 2.4)
script.inline: true
script.indexed: true
or something like:
script.disable_dynamic: false
For more information regarding dynamic scripts - https://www.elastic.co/guide/en/elasticsearch/reference/2.4/modules-scripting.html#enable-dynamic-scripting (you could select the version of Elastic that you are using)
For more inromation on function score and types of functions: https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-function-score-query.html
Upvotes: 1