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.
This commit is contained in:
Jim Ferenczi 2017-04-07 15:15:43 +02:00 committed by GitHub
parent 8522b43ce7
commit 0821fa23ff
2 changed files with 7 additions and 2 deletions

View File

@ -44,6 +44,7 @@ import org.apache.lucene.util.IOUtils;
import org.apache.lucene.util.automaton.RegExp; import org.apache.lucene.util.automaton.RegExp;
import org.elasticsearch.common.lucene.search.Queries; import org.elasticsearch.common.lucene.search.Queries;
import org.elasticsearch.common.unit.Fuzziness; import org.elasticsearch.common.unit.Fuzziness;
import org.elasticsearch.index.mapper.AllFieldMapper;
import org.elasticsearch.index.mapper.DateFieldMapper; import org.elasticsearch.index.mapper.DateFieldMapper;
import org.elasticsearch.index.mapper.MappedFieldType; import org.elasticsearch.index.mapper.MappedFieldType;
import org.elasticsearch.index.mapper.MapperService; import org.elasticsearch.index.mapper.MapperService;
@ -569,7 +570,11 @@ public class MapperQueryParser extends AnalyzingQueryParser {
@Override @Override
protected Query getWildcardQuery(String field, String termStr) throws ParseException { protected Query getWildcardQuery(String field, String termStr) throws ParseException {
if (termStr.equals("*") && field != null) { 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(); return newMatchAllDocsQuery();
} }
String actualField = field; String actualField = field;

View File

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