WARNING: Version 0.90 of Elasticsearch has passed its EOL date.
This documentation is no longer being maintained and may be removed. If you are running this version, we strongly advise you to upgrade. For the latest information, see the current release documentation.
Rescoring
editRescoring
editRescoring can help to improve precision by reordering just the top (eg
100 - 500) documents returned by the
query
and
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_type
is set
to scan
or count
.
Query rescorer
editThe query rescorer executes a second query only on the Top-K results
returned by the query
and
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
from
and size
.
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:
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 } } } '