# Can minimum\_should\_match be 'boxed'

**URL:** <https://discuss.elastic.co/t/can-minimum-should-match-be-boxed/352417>\
**Category:** Elasticsearch\
**Created:** [February 2, 2024, 3:10pm UTC](https://discuss.elastic.co/t/can-minimum-should-match-be-boxed/352417 "2024-02-02T15:10:54Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![bbaronas](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/bbaronas/32/116240_2.png) [@bbaronas](https://discuss.elastic.co/u/bbaronas)\
**Post date:** [February 2, 2024, 3:10pm UTC](https://discuss.elastic.co/t/can-minimum-should-match-be-boxed/352417/1 "2024-02-02T15:10:54Z")

</div>

Is it possible to use minimum\_should\_match to control an overabundance of should clauses in a boolean query?

For context:  
I made a query builder that allows a user to add multiple texts that get translated into individual should clauses in a boolean query. However, in some instances, this can become tens of should clauses. The query is run in a date order desc sort (no scoring) which tends to return 0 results when there are too many 'required' should clauses due to minimum\_should\_match.

The user is looking for any combination of the terms in a given query, but not necessarily all of the terms (i.e., the user is looking for any combination of "vanilla, chocolate, strawberry, butter pecan, cookie dough, rocky road, etc." where more is better, but the likelihood of finding results that contain all is not likely and matching on 1 or 2 may not be specific enough).

I am aware that minimum\_should\_match can support [multiple conditional specifications](https://www.elastic.co/guide/en/elasticsearch/reference/8.12/query-dsl-minimum-should-match.html). However, what I am looking for is a way to control an upper bound of minimum\_should\_match.

For example, I have used `minimum_should_match: 1<50%` which works well for many of the queries (in most cases, users enter less than ten items). This does a great job. However, if the number of should clauses grows too big, the results are zero (e.g., 50% of 20 should clauses are 'required').

I tried `minimum_should_match: 1<50% 10<20%` in an attempt to see if it is possible to box the should clauses to return reasonable results, but that appears not to work.

Any ideas or advice?

---

<div class="post-metadata">

**Author:** ![Mark\_Harwood1](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/mark_harwood1/32/101255_2.png) [@Mark\_Harwood1](https://discuss.elastic.co/u/Mark_Harwood1)\
**Post date:** [February 2, 2024, 8:20pm UTC](https://discuss.elastic.co/t/can-minimum-should-match-be-boxed/352417/2 "2024-02-02T20:20:00Z")

</div>

> [@bbaronas](#):
>
> The query is run in a date order desc sor

How about using score as the sort order, min\_should\_match of 1 but offering filters instead of sorting by date e.g filters “last week”, “last month” etc.? That’s how Google search handles dates.

---

<div class="post-metadata">

**Author:** ![bbaronas](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/bbaronas/32/116240_2.png) [@bbaronas](https://discuss.elastic.co/u/bbaronas)\
**Post date:** [February 7, 2024, 2:57pm UTC](https://discuss.elastic.co/t/can-minimum-should-match-be-boxed/352417/3 "2024-02-07T14:57:55Z")

</div>

The requirements are for date order descending. I provide a scored version as well, with date filtering, but in this case the requirement is to return the most recent items.

---

<div class="post-metadata">

**Author:** ![Mark\_Harwood1](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/mark_harwood1/32/101255_2.png) [@Mark\_Harwood1](https://discuss.elastic.co/u/Mark_Harwood1)\
**Post date:** [February 7, 2024, 4:53pm UTC](https://discuss.elastic.co/t/can-minimum-should-match-be-boxed/352417/4 "2024-02-07T16:53:00Z")

</div>

That’s a shame.  
Implementing this sort-by-date requirement means you are having to invent some quality filters to hide results below some arbitrary threshold. This logic will not be easily explained or controlled by end users. Alternatively, sorting by score allows users to page through all results and control the date aspects with very self-explanatory filters.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [March 6, 2024, 4:53pm UTC](https://discuss.elastic.co/t/can-minimum-should-match-be-boxed/352417/5 "2024-03-06T16:53:26Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
