Skip to content

Commit 7dc3028

Browse files
committed
Query DSL: Bool filter does not take should clauses properly into account, closes elastic#1511.
1 parent bd3a72b commit 7dc3028

File tree

1 file changed

+15
-5
lines changed

1 file changed

+15
-5
lines changed

modules/elasticsearch/src/main/java/org/elasticsearch/common/lucene/search/XBooleanFilter.java

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -79,15 +79,20 @@ public DocIdSet getDocIdSet(IndexReader reader) throws IOException {
7979
}
8080
DocSets.or(res, disi);
8181
}
82-
}
8382

84-
// if no should clauses match, return null (act as min_should_match set to 1)
85-
if (res == null) {
86-
return null;
83+
// if no should clauses match, return null (act as min_should_match set to 1)
84+
if (res == null && !shouldFilters.isEmpty()) {
85+
return null;
86+
}
8787
}
8888

89+
8990
if (notFilters != null) {
9091
for (int i = 0; i < notFilters.size(); i++) {
92+
if (res == null) {
93+
res = new FixedBitSet(reader.maxDoc());
94+
res.set(0, reader.maxDoc()); // NOTE: may set bits on deleted docs
95+
}
9196
final DocIdSet disi = getDISI(notFilters, i, reader);
9297
if (disi != null) {
9398
DocSets.andNot(res, disi);
@@ -101,7 +106,12 @@ public DocIdSet getDocIdSet(IndexReader reader) throws IOException {
101106
if (disi == null) {
102107
return null;
103108
}
104-
DocSets.and(res, disi);
109+
if (res == null) {
110+
res = new FixedBitSet(reader.maxDoc());
111+
DocSets.or(res, disi);
112+
} else {
113+
DocSets.and(res, disi);
114+
}
105115
}
106116
}
107117

0 commit comments

Comments
 (0)