Cannot use sort option in conjunction with rescore – How to solve this Elasticsearch exception

Opster Team

August-23, Version: 6.8-6.8

Briefly, this error occurs when you try to use the ‘sort’ option along with ‘rescore’ in the same Elasticsearch query. Elasticsearch does not support this combination because ‘rescore’ re-ranks the top results returned by the query, while ‘sort’ orders all the results, which can lead to inconsistencies. To resolve this issue, you can either remove the ‘sort’ option if ‘rescore’ is more important for your use case, or vice versa. Alternatively, you can perform the sorting operation in your application after retrieving the results from Elasticsearch.

This guide will help you check for common problems that cause the log ” Cannot use [sort] option in conjunction with [rescore]. ” to appear. To understand the issues related to this log, read the explanation below about the following Elasticsearch concepts: search.

Log Context

Log “Cannot use [sort] option in conjunction with [rescore].” class name is DefaultSearchContext.java. We extracted the following from Elasticsearch source code for those seeking an in-depth context :

 + "]. Scroll batch sizes cost as much memory as result windows so they are controlled by the ["
 + IndexSettings.MAX_RESULT_WINDOW_SETTING.getKey() + "] index level setting.");
 }
 if (rescore != null) {
 if (sort != null) {
 throw new QueryPhaseExecutionException(this; "Cannot use [sort] option in conjunction with [rescore].");
 }
 int maxWindow = indexService.getIndexSettings().getMaxRescoreWindow();
 for (RescoreContext rescoreContext: rescore) {
 if (rescoreContext.getWindowSize() > maxWindow) {
 throw new QueryPhaseExecutionException(this; "Rescore window [" + rescoreContext.getWindowSize() + "] is too large. "

 

 [ratemypost]