Rewrite match_all inside must_not (#85999)

A must_not with a match_all clause inside a bool query is currently not rewritten to a match_none query. This means that running a boolean query with "must_not":[{"terms":{"_tier":["data_frozen","data_cold"]}] is currently not rewritten as match_none on a cold/frozen tier node.
This commit is contained in:
Yannick Welsch 2022-04-20 08:58:19 +02:00 committed by GitHub
parent 718a241449
commit 4c47daa8d6
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 18 additions and 9 deletions

View file

@ -21,6 +21,7 @@ import org.elasticsearch.index.query.BoolQueryBuilder;
import org.elasticsearch.index.query.ConstantScoreQueryBuilder;
import org.elasticsearch.index.query.DisMaxQueryBuilder;
import org.elasticsearch.index.query.MatchAllQueryBuilder;
import org.elasticsearch.index.query.MatchNoneQueryBuilder;
import org.elasticsearch.index.query.MatchPhraseQueryBuilder;
import org.elasticsearch.index.query.MatchQueryBuilder;
import org.elasticsearch.index.query.Operator;
@ -84,10 +85,10 @@ public class QueryBuilderBWCIT extends AbstractFullClusterRestartTestCase {
""", new RangeQueryBuilder("long_field").from(1).to(9));
addCandidate(
"""
"bool": { "must_not": [{"match_all": {}}], "must": [{"match_all": {}}], "filter": [{"match_all": {}}], \
"bool": { "must_not": [{"match_none": {}}], "must": [{"match_all": {}}], "filter": [{"match_all": {}}], \
"should": [{"match_all": {}}]}
""",
new BoolQueryBuilder().mustNot(new MatchAllQueryBuilder())
new BoolQueryBuilder().mustNot(new MatchNoneQueryBuilder())
.must(new MatchAllQueryBuilder())
.filter(new MatchAllQueryBuilder())
.should(new MatchAllQueryBuilder())