Prevent skipping shards if a suggest builder is present (#25739)
Even if the query part can rewrite to match none we can't skip the suggest execution since it might yield results. Relates to #25658
This commit is contained in:
parent
ccda0441e1
commit
8364279b98
|
@ -854,8 +854,13 @@ public class SearchService extends AbstractLifecycleComponent implements IndexEv
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true iff the given search source builder can be early terminated by rewriting to a match none query. Or in other words
|
||||
* if the execution of a the search request can be early terminated without executing it. This is for instance not possible if
|
||||
* a global aggregation is part of this request or if there is a suggest builder present.
|
||||
*/
|
||||
public static boolean canRewriteToMatchNone(SearchSourceBuilder source) {
|
||||
if (source == null || source.query() == null || source.query() instanceof MatchAllQueryBuilder) {
|
||||
if (source == null || source.query() == null || source.query() instanceof MatchAllQueryBuilder || source.suggest() != null) {
|
||||
return false;
|
||||
} else {
|
||||
AggregatorFactories.Builder aggregations = source.aggregations();
|
||||
|
|
|
@ -56,6 +56,7 @@ import org.elasticsearch.search.fetch.ShardFetchRequest;
|
|||
import org.elasticsearch.search.internal.AliasFilter;
|
||||
import org.elasticsearch.search.internal.SearchContext;
|
||||
import org.elasticsearch.search.internal.ShardSearchLocalRequest;
|
||||
import org.elasticsearch.search.suggest.SuggestBuilder;
|
||||
import org.elasticsearch.test.ESSingleNodeTestCase;
|
||||
|
||||
import java.io.IOException;
|
||||
|
@ -354,5 +355,11 @@ public class SearchServiceTests extends ESSingleNodeTestCase {
|
|||
assertTrue(SearchService.canRewriteToMatchNone(new SearchSourceBuilder().query(new TermQueryBuilder("foo", "bar"))));
|
||||
assertTrue(SearchService.canRewriteToMatchNone(new SearchSourceBuilder().query(new MatchNoneQueryBuilder())
|
||||
.aggregation(new TermsAggregationBuilder("test", ValueType.STRING).minDocCount(1))));
|
||||
assertFalse(SearchService.canRewriteToMatchNone(new SearchSourceBuilder().query(new MatchNoneQueryBuilder())
|
||||
.aggregation(new TermsAggregationBuilder("test", ValueType.STRING).minDocCount(1))
|
||||
.suggest(new SuggestBuilder())));
|
||||
assertFalse(SearchService.canRewriteToMatchNone(new SearchSourceBuilder().query(new TermQueryBuilder("foo", "bar"))
|
||||
.suggest(new SuggestBuilder())));
|
||||
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue