diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/index/query/xcontent/MatchAllQueryParser.java b/modules/elasticsearch/src/main/java/org/elasticsearch/index/query/xcontent/MatchAllQueryParser.java index 1828010147c..005a95d1c35 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/index/query/xcontent/MatchAllQueryParser.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/index/query/xcontent/MatchAllQueryParser.java @@ -19,10 +19,12 @@ package org.elasticsearch.index.query.xcontent; +import org.apache.lucene.search.DeletionAwareConstantScoreQuery; import org.apache.lucene.search.MatchAllDocsQuery; import org.apache.lucene.search.Query; import org.elasticsearch.common.Strings; import org.elasticsearch.common.inject.Inject; +import org.elasticsearch.common.lucene.search.Queries; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.xcontent.XContentParser; import org.elasticsearch.index.AbstractIndexComponent; @@ -67,6 +69,10 @@ public class MatchAllQueryParser extends AbstractIndexComponent implements XCont } } + if (boost == 1.0f && normsField == null) { + return new DeletionAwareConstantScoreQuery(parseContext.cacheFilterIfPossible(Queries.MATCH_ALL_FILTER)); + } + MatchAllDocsQuery query = new MatchAllDocsQuery(normsField); query.setBoost(boost); return query;