Skip to content

Commit 1ffb1d9

Browse files
committed
add custom score query
1 parent 34d0fb4 commit 1ffb1d9

File tree

2 files changed

+37
-1
lines changed

2 files changed

+37
-1
lines changed
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
---
2+
layout: guide
3+
title: Custom Score Query
4+
cat: guide
5+
---
6+
7+
p. @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 "script expression":/guide/reference/modules/scripting. Here is a simple sample:
8+
9+
<pre class="prettyprint lang-js">
10+
"custom_score" : {
11+
"query" : {
12+
....
13+
},
14+
"script" : "_score * doc['my_numeric_field'].value"
15+
}
16+
</pre>
17+
18+
p. 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.
19+
20+
h1. Script Parameters
21+
22+
p. 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:
23+
24+
<pre class="prettyprint lang-js">
25+
"custom_score" : {
26+
"query" : {
27+
....
28+
},
29+
"params" : {
30+
"param1" : 2,
31+
"param2" : 3.1
32+
}
33+
"script" : "_score * doc['my_numeric_field'].value / pow(param1, param2)"
34+
}
35+
</pre>

guide/reference/query-dsl/sidebar.textile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@ h3. "Guide":/guide
77
h3. Queries
88

99
* "bool":bool-query.html
10-
* "contant_score":constant-score-query.html
10+
* "custom_score":custom-score-query.html
11+
* "constant_score":constant-score-query.html
1112
* "dis_max":dis-max-query.html
1213
* "field":field-query.html
1314
* "filtered":filtered-query.html

0 commit comments

Comments
 (0)