summaryrefslogtreecommitdiff
path: root/docs/reference/search/request/rescore.asciidoc
blob: 50112648772b1efbc953d0526ba73087ae4d0969 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
[[search-request-rescore]]
=== Rescoring

Rescoring can help to improve precision by reordering just the top (eg
100 - 500) documents returned by the
<<search-request-query,`query`>> and
<<search-request-post-filter,`post_filter`>> phases, using a
secondary (usually more costly) algorithm, instead of applying the
costly algorithm to all documents in the index.

A `rescore` request is executed on each shard before it returns its
results to be sorted by the node handling the overall search request.

Currently the rescore API has only one implementation: the query
rescorer, which uses a query to tweak the scoring. In the future, 
alternative rescorers may be made available, for example, a pair-wise rescorer.

*Note:* the `rescore` phase is not executed when
<<search-request-search-type,`search_type`>> is set
to `scan` or `count`.

==== Query rescorer

The query rescorer executes a second query only on the Top-K results
returned by the <<search-request-query,`query`>> and
<<search-request-post-filter,`post_filter`>> phases. The
number of docs which will be examined on each shard can be controlled by
the `window_size` parameter, which defaults to
<<search-request-from-size,`from` and `size`>>.

By default the scores from the original query and the rescore query are
combined linearly to produce the final `_score` for each document. The
relative importance of the original query and of the rescore query can
be controlled with the `query_weight` and `rescore_query_weight`
respectively. Both default to `1`.

For example:

[source,js]
--------------------------------------------------
curl -s -XPOST 'localhost:9200/_search' -d '{
   "query" : {
      "match" : {
         "field1" : {
            "operator" : "or",
            "query" : "the quick brown",
            "type" : "boolean"
         }
      }
   },
   "rescore" : {
      "window_size" : 50,
      "query" : {
         "rescore_query" : {
            "match" : {
               "field1" : {
                  "query" : "the quick brown",
                  "type" : "phrase",
                  "slop" : 2
               }
            }
         },
         "query_weight" : 0.7,
         "rescore_query_weight" : 1.2
      }
   }
}
'
--------------------------------------------------

The way the scores are combined can be controled with the `score_mode`:
[cols="<,<",options="header",]
|=======================================================================
|Score Mode |Description
|`total`    |Add the original score and the rescore query score.  The default.
|`multiply` |Multiply the original score by the rescore query score.  Useful
for <<query-dsl-function-score-query,`function query`>> rescores.
|`avg`      |Average the original score and the rescore query score.
|`max`      |Take the max of original score and the rescore query score.
|`min`      |Take the min of the original score and the rescore query score.
|=======================================================================