Skip to content

Commit

Permalink
Restore special case for wilcard on _all query to rewrite to a match …
Browse files Browse the repository at this point in the history
…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.
  • Loading branch information
jimczi committed Apr 7, 2017
1 parent 575ca9e commit ea19947
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
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.LegacyDateFieldMapper;
import org.elasticsearch.index.mapper.MappedFieldType;
Expand Down Expand Up @@ -574,7 +575,11 @@ private Query getPossiblyAnalyzedPrefixQuery(String field, String termStr) throw
@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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -854,7 +854,7 @@ public void testExistsFieldQuery() throws Exception {

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("*:*");
Expand Down

0 comments on commit ea19947

Please sign in to comment.