OpenSearch/docs/reference/query-dsl/queries/custom-score-query.asciidoc

46 lines
1.2 KiB
Plaintext
Raw Normal View History

[[query-dsl-custom-score-query]]
=== Custom Score Query
deprecated[0.90.4,Replaced by <<query-dsl-function-score-query>>]
2013-09-04 15:59:46 -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)"
}
--------------------------------------------------