# Equivalent of a maximum\_should\_match?

**URL:** <https://discuss.elastic.co/t/equivalent-of-a-maximum-should-match/42791>\
**Category:** Elasticsearch\
**Created:** [February 25, 2016, 11:26pm UTC](https://discuss.elastic.co/t/equivalent-of-a-maximum-should-match/42791 "2016-02-25T23:26:45Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![feicipet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/feicipet/32/8056_2.png) [@feicipet](https://discuss.elastic.co/u/feicipet)\
**Post date:** [February 25, 2016, 11:26pm UTC](https://discuss.elastic.co/t/equivalent-of-a-maximum-should-match/42791/1 "2016-02-25T23:26:45Z")

</div>

I have a "should" block in my bool query that contains 3 conditions. It would match anything that matches any 1 or more of the 3 conditions. But I would like to exclude anything that matches all 3 conditions, i.e. only match 1 or 2 of the conditions. Is there something like a maximum\_should\_match that would give me the equivalent of this?

Thanks  
Wong

---

<div class="post-metadata">

**Author:** ![feicipet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/feicipet/32/8056_2.png) [@feicipet](https://discuss.elastic.co/u/feicipet)\
**Post date:** [February 26, 2016, 10:44am UTC](https://discuss.elastic.co/t/equivalent-of-a-maximum-should-match/42791/2 "2016-02-26T10:44:57Z")

</div>

I've found out that I can construct my query using `query_string`, which looks something like this:

`(ResponseQ1:0 OR ResponseQ2:0 OR ResponseQ3:<skipped>) AND NOT (ResponseQ1:0 AND ResponseQ2:0 AND ResponseQ3:<skipped>)`

---

<div class="post-metadata">

**Author:** ![nik9000](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/nik9000/32/44947_2.png) [@nik9000](https://discuss.elastic.co/u/nik9000)\
**Post date:** [February 26, 2016, 5:47pm UTC](https://discuss.elastic.co/t/equivalent-of-a-maximum-should-match/42791/3 "2016-02-26T17:47:30Z")

</div>

You can also do the same with a bool query and a `must_not` clause containing a should clause. Like:

```auto
{
  "query": {
    "bool": {
      "minimum_should_match": 1,
      "should": [your queries],
       "must_not": [
        "bool": {
          "minimum_should_match": 3, <---- this is your maximum_should_match
          "should": [your queries again]
        }
      ]
    }
  }
}

```

Its the same as your query\_string way but keeps you in the DSL. Its not as good as having native `maximum_should_match` though because it has to evaluate the queries twice. But if it is fast enough then it is fast enough.

---

<div class="post-metadata">

**Author:** ![feicipet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/feicipet/32/8056_2.png) [@feicipet](https://discuss.elastic.co/u/feicipet)\
**Post date:** [February 27, 2016, 4:03pm UTC](https://discuss.elastic.co/t/equivalent-of-a-maximum-should-match/42791/4 "2016-02-27T16:03:29Z")

</div>

I got a parse error running this search in Kibana. I think the DSL doesn't allow you to embed another "bool" query inside any of the higher level "bool"'s subconditions... I did try some variation of that in my earlier attempts and that's what stopped me.

---

<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:** [July 5, 2017, 11:13pm UTC](https://discuss.elastic.co/t/equivalent-of-a-maximum-should-match/42791/5 "2017-07-05T23:13:07Z")

</div>


