# Difference between should clause with minimum\_should\_match and should clause inside a must clause

**URL:** <https://discuss.elastic.co/t/difference-between-should-clause-with-minimum-should-match-and-should-clause-inside-a-must-clause/217183>\
**Category:** Elasticsearch\
**Created:** [January 30, 2020, 12:41pm UTC](https://discuss.elastic.co/t/difference-between-should-clause-with-minimum-should-match-and-should-clause-inside-a-must-clause/217183 "2020-01-30T12:41:42Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![pilo](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/pilo/32/46015_2.png) [@pilo](https://discuss.elastic.co/u/pilo)\
**Post date:** [January 30, 2020, 12:41pm UTC](https://discuss.elastic.co/t/difference-between-should-clause-with-minimum-should-match-and-should-clause-inside-a-must-clause/217183/1 "2020-01-30T12:41:42Z")

</div>

Hello everyone,  
I'm doing a request using `should` and `filter` clauses like this

```auto
GET case/_search
{
  "_source": false,
  "query": {
    "bool": {
      "should": [
        {
          "multi_match": {
            "query": "france",
            "fields": [
              "translations.en.title",
              "translations.en.title2"
            ]
          }
        },
        {
          "nested": {
            "path": "nested_articles",
            "query": {
              "multi_match": {
                "query": "france",
                "fields": [
                  "nested_articles.level_title",
                  "nested_articles.article_title.",   
                ]
              }
            }
          }
        }
      ],
      "filter": {
        "range": {
          "adoption_date": {
            "lte": "2013-03-21T23:00:00.000Z"
          }
        }
      }
    }
  }
}

```

After doing some research, i found out that if i put `filter` clause with `should` clause like above, `should` clause became optional and elasticsearch returns the result matched the `filter` clause, regardless `should` clause

That is when i came up with two solutions.

The first one is putting `should` clause inside a `must` clause, and then combine this `must` clause with `filter` clause (like bellow)

```auto
GET case/_search
{
  "query": {
    "bool": {
      "must": {
        "bool": {
          "should": [
            {
              "multi_match": {
                "query": "france",
                "fields": [
                  "translations.en.title",
                  "translations.en.title2"
                ]
              }
            },
            {
              "nested": {
                "path": "nested_articles",
                "query": {
                  "multi_match": {
                    "query": "france",
                    "fields": [
                      "nested_articles.level_title.en",
                      "nested_articles.article_title.en",
                      "nested_articles.content.en"
                    ]
                  }
                }
              }
            }
          ]
        }
      },
      "filter": {
        "range": {
          "adoption_date": {
            "lte": "2020-03-21T23:00:00.000Z"
          }
        }
      }
    }
  }
}

```

The secoud one is using `minimum_should_match`, in this case is **1** (like bellow)

```auto
GET case/_search
{
  "query": {
    "bool": {
      "must": {
        "bool": {
          "should": [
            {
              "multi_match": {
                "query": "france",
                "fields": [
                  "translations.en.title",
                  "translations.en.title2"
                ]
              }
            },
            {
              "nested": {
                "path": "nested_articles",
                "query": {
                  "multi_match": {
                    "query": "france",
                    "fields": [
                      "nested_articles.level_title.en",
                      "nested_articles.article_title.en",
                      "nested_articles.content.en"
                    ]
                  }
                }
              }
            }
          ]
        }
      },
      "filter": {
        "range": {
          "adoption_date": {
            "lte": "2020-03-21T23:00:00.000Z"
          }
        }
      },
      "minimum_should_match": 1
    }
  }
}

```

The number of results was returned is differents. The first solution has 124 hits and the second one has 122 hits.  
What is the difference between these two query ?  
Are there any better solution than these two solution above ?  
Thank you in advance for your answer.

---

<div class="post-metadata">

**Author:** ![pilo](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/pilo/32/46015_2.png) [@pilo](https://discuss.elastic.co/u/pilo)\
**Post date:** [January 31, 2020, 11:00am UTC](https://discuss.elastic.co/t/difference-between-should-clause-with-minimum-should-match-and-should-clause-inside-a-must-clause/217183/2 "2020-01-31T11:00:39Z")

</div>

anyone, pls help 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:** [February 28, 2020, 11:00am UTC](https://discuss.elastic.co/t/difference-between-should-clause-with-minimum-should-match-and-should-clause-inside-a-must-clause/217183/3 "2020-02-28T11:00:42Z")

</div>

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