# Combining queries with "must" and "should"

**URL:** <https://discuss.elastic.co/t/combining-queries-with-must-and-should/57636>\
**Category:** Elasticsearch\
**Created:** [August 9, 2016, 11:54pm UTC](https://discuss.elastic.co/t/combining-queries-with-must-and-should/57636 "2016-08-09T23:54:28Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![pku](https://avatars.discourse-cdn.com/v4/letter/p/82dd89/32.png) [@pku](https://discuss.elastic.co/u/pku)\
**Post date:** [August 9, 2016, 11:54pm UTC](https://discuss.elastic.co/t/combining-queries-with-must-and-should/57636/1 "2016-08-09T23:54:28Z")

</div>

I am struggling with understanding the behavior of "must" and "should" .  
Following is my search query,

```
GET listings/_search?
{
  "query": {
     "bool": {
     "must": [
      { "match": { "city": "Terre Haute" }},
      { "match": { "state": "IN" }},
      { "match": { "listing" : "wal mart pharmacy"}}
     ]
      , "should": [
        {"match": {
         "caplist": "main general information customer service store line"
      }}
     ]
  }
 },
"_source": ["listing", "caplist","city","state","telnum"]
}

```

and the top two results it returns are as follows,

```
  "took": 8,
  "timed_out": false,
  "_shards": {
  "total": 5,
  "successful": 5,
  "failed": 0
  },
  "hits": {
  "total": 46,
 "max_score": 8.381018,
 "hits": [
  {
    "_index": "listings",
    "_type": "listings",
    "_id": "e62e6314f3a5951a27e6954d519c7431",
    "_score": 8.381018,
    "_source": {
      "city": "Terre Haute",
      "state": "IN",
      "caplist": "Main Store Line;",
      "listing": "Wal Mart",
      "telnum": "8128722520"
    }
  },
  {
    "_index": "listings",
    "_type": "listings",
    "_id": "4d3dbd1e1012fae7efb9b86b032f258a",
    "_score": 5.925434,
    "_source": {
      "city": "Terre Haute",
      "state": "IN",
      "caplist": "",
      "listing": "Wal-Mart Pharmacy -10-4235",
       "telnum": "8128722314"
     }

```

I had expected the order to be the other way round ( That is what I want) i.e. the document where "listing" : "Wal-Mart Pharmacy -10-4235" to be ranked higher as the "must" field has all the three words "wal","mart" and "pharmacy".  
I read the documentation and I understood that all the "must" clauses must be matched and "should" can be optional.  
What I want is to rank the documents higher where all words in the "must" clauses match and "should" clause is just to boost the score once all the "must" is matched.  
what changes should I make to me search query to score the "listing": "Wal-Mart Pharmacy -10-4235" higher than "listing": "Wal Mart".  
I am just a beginner in Elasticsearch. Any help would be appreciated.  
Thanks!

---

<div class="post-metadata">

**Author:** ![ywelsch](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ywelsch/32/7751_2.png) [@ywelsch](https://discuss.elastic.co/u/ywelsch)\
**Post date:** [August 10, 2016, 9:52am UTC](https://discuss.elastic.co/t/combining-queries-with-must-and-should/57636/2 "2016-08-10T09:52:16Z")

</div>

you could boost the must matches, see for example:

[https://www.elastic.co/guide/en/elasticsearch/guide/current/query-time-boosting.html](https://www.elastic.co/guide/en/elasticsearch/guide/current/query-time-boosting.html)

---

<div class="post-metadata">

**Author:** ![pku](https://avatars.discourse-cdn.com/v4/letter/p/82dd89/32.png) [@pku](https://discuss.elastic.co/u/pku)\
**Post date:** [August 10, 2016, 5:00pm UTC](https://discuss.elastic.co/t/combining-queries-with-must-and-should/57636/3 "2016-08-10T17:00:27Z")

</div>

Thanks. That worked but I had to give it a really high boost ( boost =8) are there any rules as to how to decide this boost factor.

---

<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, 10:28pm UTC](https://discuss.elastic.co/t/combining-queries-with-must-and-should/57636/4 "2017-07-05T22:28:42Z")

</div>


