Skip to content

Commit 42ae147

Browse files
committed
Reset minimum_should_match in Bool.__and__
Fixes #890
1 parent 0766e26 commit 42ae147

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

elasticsearch_dsl/query.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,11 @@ def __and__(self, other):
148148
q.must_not += other.must_not
149149
q.filter += other.filter
150150
q.should = []
151+
152+
# reset minimum_should_match as it will get calculated below
153+
if 'minimum_should_match' in q._params:
154+
del q._params['minimum_should_match']
155+
151156
for qx in (self, other):
152157
# TODO: percentages will fail here
153158
min_should_match = qx._min_should_match

test_elasticsearch_dsl/test_query.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,13 @@ def test_bool_and_bool():
163163
q2 = query.Bool(should=[qt3])
164164
assert q1 & q2 == query.Bool(must=[qt1, qt3], should=[qt1, qt2], minimum_should_match=0)
165165

166+
def test_bool_and_bool_with_min_should_match():
167+
qt1, qt2 = query.Match(f=1), query.Match(f=2)
168+
q1 = query.Q('bool', minimum_should_match=1, should=[qt1])
169+
q2 = query.Q('bool', minimum_should_match=1, should=[qt2])
170+
171+
assert query.Q('bool', must=[qt1, qt2]) == q1 & q2
172+
166173
def test_inverted_query_becomes_bool_with_must_not():
167174
q = query.Match(f=42)
168175

0 commit comments

Comments
 (0)