Browse Source

Restore special case for wilcard on _all query to rewrite to a match all query (#23967)

This change restores the rewrite to a match all query that we used to apply on wildcard query * on the query_string parser before #23433.
Jim Ferenczi 8 years ago
parent
commit
0821fa23ff

+ 6 - 1
core/src/main/java/org/apache/lucene/queryparser/classic/MapperQueryParser.java

@@ -44,6 +44,7 @@ import org.apache.lucene.util.IOUtils;
 import org.apache.lucene.util.automaton.RegExp;
 import org.elasticsearch.common.lucene.search.Queries;
 import org.elasticsearch.common.unit.Fuzziness;
+import org.elasticsearch.index.mapper.AllFieldMapper;
 import org.elasticsearch.index.mapper.DateFieldMapper;
 import org.elasticsearch.index.mapper.MappedFieldType;
 import org.elasticsearch.index.mapper.MapperService;
@@ -569,7 +570,11 @@ public class MapperQueryParser extends AnalyzingQueryParser {
     @Override
     protected Query getWildcardQuery(String field, String termStr) throws ParseException {
         if (termStr.equals("*") && field != null) {
-            if ("*".equals(field)) {
+            /**
+             * We rewrite _all:* to a match all query.
+             * TODO: We can remove this special case when _all is completely removed.
+             */
+            if ("*".equals(field) || AllFieldMapper.NAME.equals(field)) {
                 return newMatchAllDocsQuery();
             }
             String actualField = field;

+ 1 - 1
core/src/test/java/org/elasticsearch/index/query/QueryStringQueryBuilderTests.java

@@ -822,7 +822,7 @@ public class QueryStringQueryBuilderTests extends AbstractQueryTestCase<QueryStr
 
         queryBuilder = new QueryStringQueryBuilder("_all:*");
         query = queryBuilder.toQuery(context);
-        expected = new ConstantScoreQuery(new TermQuery(new Term("_field_names", "_all")));
+        expected = new MatchAllDocsQuery();
         assertThat(query, equalTo(expected));
 
         queryBuilder = new QueryStringQueryBuilder("*:*");