# Elastic Search “should” clause not working as expected when “should”, “must” and “must\_not” clause are present

**URL:** <https://discuss.elastic.co/t/elastic-search-should-clause-not-working-as-expected-when-should-must-and-must-not-clause-are-present/70231>\
**Category:** Elasticsearch\
**Created:** [December 29, 2016, 7:16pm UTC](https://discuss.elastic.co/t/elastic-search-should-clause-not-working-as-expected-when-should-must-and-must-not-clause-are-present/70231 "2016-12-29T19:16:20Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![bandikishores](https://avatars.discourse-cdn.com/v4/letter/b/b5a626/32.png) [@bandikishores](https://discuss.elastic.co/u/bandikishores)\
**Post date:** [December 29, 2016, 7:16pm UTC](https://discuss.elastic.co/t/elastic-search-should-clause-not-working-as-expected-when-should-must-and-must-not-clause-are-present/70231/1 "2016-12-29T19:16:20Z")

</div>

I've loaded the data provided [here](https://raw.githubusercontent.com/elastic/elasticsearch/master/docs/src/test/resources/accounts.json) into elastic search.

Now I'm trying to query for Accounts.

1. Age Must be 38.
2. State Should not be "ID".
3. **Address Should Contain Either** : (This is not Working)
  - The text "lane" OR
  - The a complete text "mill avenue"

**Request** : POST - [http://localhost:9200/bank/account/\_search?pretty](http://localhost:9200/bank/account/_search?pretty)

```
{
  "query": {
    "bool": {
      "should": [
        { "match": { "address": "lane" } },
        { "match_phrase": { "address": "mill avenue" } }
      ],
      "must": [
        { "match": { "age": "38" } }
      ],
      "must_not": [
        { "match": { "state": "ID" } }
      ]
    }
  },
  "from": 0,
  "size": 1,
  "_source": ["account_number", "balance", "firstname", "lastname", "age", "email", "address", "state"],
  "sort": [
    { "account_number": "asc" },
    { "balance": "desc"}
  ]
}

```

**Response** :

```
{
  "took": 8,
  "timed_out": false,
  "_shards": {
    "total": 5,
    "successful": 5,
    "failed": 0
  },
  "hits": {
    "total": 36,
    "max_score": null,
    "hits": [
      {
        "_index": "bank",
        "_type": "account",
        "_id": "21",
        "_score": null,
        "_source": {
          "account_number": 21,
          "firstname": "Estella",
          "address": "859 Portal Street",
          "balance": 7004,
          "state": "WV",
          "age": 38,
          "email": "estellapaul@zillatide.com",
          "lastname": "Paul"
        },
        "sort": [
          21,
          7004
        ]
      }
    ]
  }
}

```

You can check the response. The record with address **"859 Portal Street"** was received and **it doesn't contain "lane" or "mill avenue"**.

Elastic Search Version : 5.1.1

---

<div class="post-metadata">

**Author:** ![mattweber](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/mattweber/32/44940_2.png) [@mattweber](https://discuss.elastic.co/u/mattweber)\
**Post date:** [December 29, 2016, 10:07pm UTC](https://discuss.elastic.co/t/elastic-search-should-clause-not-working-as-expected-when-should-must-and-must-not-clause-are-present/70231/2 "2016-12-29T22:07:58Z")

</div>

You need to set minimum\_should\_match value to 1 otherwise BOTH should clauses are optional due to having the must/must\_not clauses. If all you had were should clauses, minimum\_should\_match would not be needed because it defaults to a value of one in that scenario.

---

<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:** [January 26, 2017, 10:08pm UTC](https://discuss.elastic.co/t/elastic-search-should-clause-not-working-as-expected-when-should-must-and-must-not-clause-are-present/70231/3 "2017-01-26T22:08:01Z")

</div>

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