2013-08-28 19:24:34 -04:00
|
|
|
[[query-dsl-custom-score-query]]
|
|
|
|
=== Custom Score Query
|
|
|
|
|
2013-09-04 15:59:46 -04:00
|
|
|
deprecated[1.00.Beta,Replaced by <<query-dsl-function-score-query>>]
|
|
|
|
|
2013-08-28 19:24:34 -04:00
|
|
|
`custom_score` query allows to wrap another query and customize the
|
|
|
|
scoring of it optionally with a computation derived from other field
|
|
|
|
values in the doc (numeric ones) using
|
|
|
|
<<modules-scripting,script expression>>. Here is
|
|
|
|
a simple sample:
|
|
|
|
|
|
|
|
[source,js]
|
|
|
|
--------------------------------------------------
|
|
|
|
"custom_score" : {
|
|
|
|
"query" : {
|
|
|
|
....
|
|
|
|
},
|
|
|
|
"script" : "_score * doc['my_numeric_field'].value"
|
|
|
|
}
|
|
|
|
--------------------------------------------------
|
|
|
|
|
|
|
|
On top of the different scripting field values and expression, the
|
|
|
|
`_score` script parameter can be used to retrieve the score based on the
|
|
|
|
wrapped query.
|
|
|
|
|
|
|
|
[float]
|
|
|
|
==== Script Parameters
|
|
|
|
|
|
|
|
Scripts are cached for faster execution. If the script has parameters
|
|
|
|
that it needs to take into account, it is preferable to use the same
|
|
|
|
script, and provide parameters to it:
|
|
|
|
|
|
|
|
[source,js]
|
|
|
|
--------------------------------------------------
|
|
|
|
"custom_score" : {
|
|
|
|
"query" : {
|
|
|
|
....
|
|
|
|
},
|
|
|
|
"params" : {
|
|
|
|
"param1" : 2,
|
|
|
|
"param2" : 3.1
|
|
|
|
},
|
|
|
|
"script" : "_score * doc['my_numeric_field'].value / pow(param1, param2)"
|
|
|
|
}
|
|
|
|
--------------------------------------------------
|