From 0821fa23ffa00d449e9deacf15db0c3331bed360 Mon Sep 17 00:00:00 2001 From: Jim Ferenczi Date: Fri, 7 Apr 2017 15:15:43 +0200 Subject: [PATCH] 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. --- .../lucene/queryparser/classic/MapperQueryParser.java | 7 ++++++- .../index/query/QueryStringQueryBuilderTests.java | 2 +- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/core/src/main/java/org/apache/lucene/queryparser/classic/MapperQueryParser.java b/core/src/main/java/org/apache/lucene/queryparser/classic/MapperQueryParser.java index c0c48767529..2b592aa935f 100644 --- a/core/src/main/java/org/apache/lucene/queryparser/classic/MapperQueryParser.java +++ b/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; diff --git a/core/src/test/java/org/elasticsearch/index/query/QueryStringQueryBuilderTests.java b/core/src/test/java/org/elasticsearch/index/query/QueryStringQueryBuilderTests.java index 38e23bd5d50..28bc9c83a50 100644 --- a/core/src/test/java/org/elasticsearch/index/query/QueryStringQueryBuilderTests.java +++ b/core/src/test/java/org/elasticsearch/index/query/QueryStringQueryBuilderTests.java @@ -822,7 +822,7 @@ public class QueryStringQueryBuilderTests extends AbstractQueryTestCase