# Rollup job - should and minimum\_should\_match not working

**URL:** <https://discuss.elastic.co/t/rollup-job-should-and-minimum-should-match-not-working/303829>\
**Category:** Elasticsearch\
**Tags:** rollups\
**Created:** [May 3, 2022, 12:30pm UTC](https://discuss.elastic.co/t/rollup-job-should-and-minimum-should-match-not-working/303829 "2022-05-03T12:30:05Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![hunsw](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/hunsw/32/93637_2.png) [@hunsw](https://discuss.elastic.co/u/hunsw)\
**Post date:** [May 3, 2022, 12:30pm UTC](https://discuss.elastic.co/t/rollup-job-should-and-minimum-should-match-not-working/303829/1 "2022-05-03T12:30:05Z")

</div>

When querying rollup jobs `minimum_should_match` is not working (v7.17) making `should` clauses useless.

Is there a fix/workaround for this?

The rollup job limitations page lists compound queries explicitly as allowed ones, so in theory it **should** work.

---

<div class="post-metadata">

**Author:** ![warkolm](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/warkolm/32/39224_2.png) [@warkolm](https://discuss.elastic.co/u/warkolm)\
**Post date:** [May 5, 2022, 2:18am UTC](https://discuss.elastic.co/t/rollup-job-should-and-minimum-should-match-not-working/303829/2 "2022-05-05T02:18:58Z")

</div>

I may not be able to directly help here, but it'd be useful if you showed your rollup job, the output you are getting, and how that differs from what you expect.

---

<div class="post-metadata">

**Author:** ![hunsw](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/hunsw/32/93637_2.png) [@hunsw](https://discuss.elastic.co/u/hunsw)\
**Post date:** [May 5, 2022, 7:27am UTC](https://discuss.elastic.co/t/rollup-job-should-and-minimum-should-match-not-working/303829/3 "2022-05-05T07:27:29Z")

</div>

Thank you for taking the time to answer.

I've created a paste here: [https://pastebin.com/6bJPp8mT](https://pastebin.com/6bJPp8mT) that creates a sample index (`cardata`, but it has totally bogus data), puts 5 docs into it then creates and starts a rollup job. (It also cleans up after itself (L41-43).)

Should I file a bug in GitHub? Or am I doing something wrong? 🙂

---

<div class="post-metadata">

**Author:** ![Mark\_Harwood](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/mark_harwood/32/10538_2.png) [@Mark\_Harwood](https://discuss.elastic.co/u/Mark_Harwood)\
**Post date:** [May 5, 2022, 7:52am UTC](https://discuss.elastic.co/t/rollup-job-should-and-minimum-should-match-not-working/303829/4 "2022-05-05T07:52:45Z")

</div>

A ‘should’ clause clause is only mandatory if it is on its own in a ‘bool’ clause. When it is alongside a must/filter/must\_not it is relegated to an optional clause that gives extra points to scores of docs matching the other mandatory clauses.  
To make a should act as a mandatory set of ORed choices it can often be necessary to wrap it in a bool container on its own and then embed that as a must inside the main bool query.

---

<div class="post-metadata">

**Author:** ![hunsw](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/hunsw/32/93637_2.png) [@hunsw](https://discuss.elastic.co/u/hunsw)\
**Post date:** [May 5, 2022, 9:41am UTC](https://discuss.elastic.co/t/rollup-job-should-and-minimum-should-match-not-working/303829/5 "2022-05-05T09:41:16Z")

</div>

It seems to me that with an extra bool, the result is the same: the 'normal' search works, the rollup search does not.

Using the dataset from my pastebin link above, this 'normal' query returns GBP and amount 17.

If you replace the index name to `rollup-cardata` and the API endpoint to `_rollup_search`, you get 0 hits. (Interestingly, if I leave `should` clause as a 2nd filter (on the same level as the term:currency:GBP), I get the erroneous operation I mentioned in the op (GBP and 82 as amount).

```auto
GET cardata/_search?size=0
{
  "query": {
    "bool": {
      "filter": [
        {
          "term": {
            "currency": "GBP"
          }
        },
        {
          "bool": {
            "should": [
              {
                "term": {
                  "car.original_state": "CLEAN"
                }
              },
              {
                "term": {
                  "car.original_state": "UPGRADED"
                }
              }
            ],
            "minimum_should_match": 1
          }
        }
      ]
    }
  },
  "aggs": {
    "currency_agg": {
      "terms": {
        "field": "currency"
      },
      "aggs": {
        "amount_agg": {
          "sum": {
            "field": "amount"
          }
        }
      }
    }
  }
}

```

---

<div class="post-metadata">

**Author:** ![Mark\_Harwood](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/mark_harwood/32/10538_2.png) [@Mark\_Harwood](https://discuss.elastic.co/u/Mark_Harwood)\
**Post date:** [May 5, 2022, 3:23pm UTC](https://discuss.elastic.co/t/rollup-job-should-and-minimum-should-match-not-working/303829/6 "2022-05-05T15:23:05Z")

</div>

I’ll leave it to others to diagnose why the roll up query may not be working in this case but the comment on the bool/should logic still stands.

---

<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:** [June 2, 2022, 3:23pm UTC](https://discuss.elastic.co/t/rollup-job-should-and-minimum-should-match-not-working/303829/7 "2022-06-02T15:23:32Z")

</div>

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