# Elastic eng I, should not (should + must\_not)

**URL:** <https://discuss.elastic.co/t/elastic-eng-i-should-not-should-must-not/173476>\
**Category:** Elastic Training\
**Created:** [March 22, 2019, 10:52am UTC](https://discuss.elastic.co/t/elastic-eng-i-should-not-should-must-not/173476 "2019-03-22T10:52:32Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![nsam](https://avatars.discourse-cdn.com/v4/letter/n/ecd19e/32.png) [@nsam](https://discuss.elastic.co/u/nsam)\
**Post date:** [March 22, 2019, 10:52am UTC](https://discuss.elastic.co/t/elastic-eng-i-should-not-should-must-not/173476/1 "2019-03-22T10:52:32Z")

</div>

hello

reviewing the elasting eng I material  
I came across the topic "nest bool query (Slide 170)" ...  
Why does this example influence max\_score (is higher) but not the hits total?

Is there a simple explantation?

---

<div class="post-metadata">

**Author:** ![raposa](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/raposa/32/11906_2.png) [@raposa](https://discuss.elastic.co/u/raposa)\
**Post date:** [March 22, 2019, 1:09pm UTC](https://discuss.elastic.co/t/elastic-eng-i-should-not-should-must-not/173476/3 "2019-03-22T13:09:22Z")

</div>

Adding a `should` clause to a `bool` query that contains a `must` clause does not change the number of hits, only the scoring.

For example, the following `match` query searches for blogs that mention "logstash" in the `content` field. Suppose you get 140 hits:

```auto
GET blogs/_search
{
  "query": {
    "match": {
      "content": "logstash"
    }
  }
}

```

Now let's add a `should` clause, so that blogs with "logstash" in the `title` field of the blog score higher (we are still requiring the "logstash" is in the `content` field):

```auto
GET blogs/_search
{
  "query": {
    "bool": {
      "must": {
        "match": {
          "content": "logstash"
        }
      },
      "should": {
        "match": {
          "title": "logstash"
        }
      }
    }
  }
}

```

The `should` clause does not add any hits to the results. Think about the English word "should" - it is not a _requirement_ that "logstash" be in the title, rather it is something that we would _prefer_ to have in our hits.

So in the `bool` query above, you would still get 140 hits. But if a blog has "logstash" in the `title` also, then the score from that `should` clause is **added** to the score from the `must` clause. In this example above, the max\_score would be considerably higher for blogs that have "logstash" in the title. If a blog does _not_ have "logstash" in the title, then its score from the `bool` query will be the same as if you ran the `match` query without a `should` clause.

---

<div class="post-metadata">

**Author:** ![pmusa](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/pmusa/32/3498_2.png) [@pmusa](https://discuss.elastic.co/u/pmusa)\
**Post date:** [March 22, 2019, 1:12pm UTC](https://discuss.elastic.co/t/elastic-eng-i-should-not-should-must-not/173476/4 "2019-03-22T13:12:51Z")

</div>

Hi nsam,  
it is because the match\_phrase is inside a should clause. Any clause inside the `must` must happen. Any clause inside the `should` should happen. In other words, any clause inside a should will not discard results, but will impact the score of the documents that match the `should`. Not sure that is clear, but hopefully you could understand.

Cheers

---

<div class="post-metadata">

**Author:** ![nsam](https://avatars.discourse-cdn.com/v4/letter/n/ecd19e/32.png) [@nsam](https://discuss.elastic.co/u/nsam)\
**Post date:** [March 22, 2019, 1:36pm UTC](https://discuss.elastic.co/t/elastic-eng-i-should-not-should-must-not/173476/5 "2019-03-22T13:36:25Z")

</div>

@raposa & @pmusa

both explanation help me to undesrstand ...  
so to sum up, the should clause boost the \_score and don't influence total count.

thank you

---

<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:** [April 21, 2019, 1:51pm UTC](https://discuss.elastic.co/t/elastic-eng-i-should-not-should-must-not/173476/6 "2019-04-21T13:51:18Z")

</div>

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