Skip to content

Commit 4dec14d

Browse files
committed
Wildcard query on non existent field matches all documents
fixes elastic#2461
1 parent ea9a4d7 commit 4dec14d

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

src/main/java/org/apache/lucene/queryparser/classic/MapperQueryParser.java

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -555,7 +555,18 @@ protected Query getWildcardQuery(String field, String termStr) throws ParseExcep
555555
if (termStr.equals("*")) {
556556
// we want to optimize for match all query for the "*:*", and "*" cases
557557
if ("*".equals(field) || Objects.equal(field, this.field)) {
558-
return newMatchAllDocsQuery();
558+
String actualField = field;
559+
if (actualField == null) {
560+
actualField = this.field;
561+
}
562+
if (actualField == null) {
563+
return newMatchAllDocsQuery();
564+
}
565+
if ("_all".equals(actualField)) {
566+
return newMatchAllDocsQuery();
567+
}
568+
// effectively, we check if a field exists or not
569+
return fieldQueryExtensions.get(ExistsFieldQueryExtension.NAME).query(parseContext, actualField);
559570
}
560571
}
561572
Collection<String> fields = extractMultiFields(field);

0 commit comments

Comments
 (0)