# Help understanding boolean query and boosting?

**URL:** https://discuss.elastic.co/t/help-understanding-boolean-query-and-boosting/337842
**Category:** Elasticsearch
**Created:** [July 6, 2023, 8:08pm UTC](https://discuss.elastic.co/t/help-understanding-boolean-query-and-boosting/337842 "2023-07-06T20:08:13Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![reswob](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/reswob/32/38015_2.png) [@reswob](https://discuss.elastic.co/u/reswob)
#### Post date: [July 6, 2023, 8:08pm UTC](https://discuss.elastic.co/t/help-understanding-boolean-query-and-boosting/337842/1 "2023-07-06T20:08:13Z")

</div>

So I'm doing some self training in my lab. I wanted to create a query looking for value A in field A OR value B in field B and return all records that met that either criteria. Value A is type long and value B is text

I've been trying to use match, multi\_match, and boolean filters.

This doesn't work:

```auto
GET index/_search
{
   "query" : {
      "match" : {
          "fieldA" : valueA,
          "fieldB" : "valueB"
      }
   }
}

```

neither does this:

```auto
GET index/_search
{
   "query" : {
      "multi_match" : {
          "query" : "valueA valueB",
          "fields" : ["fieldA", "fieldB"]
      }
   }
}

```

This works:

```auto
GET index/_search
{
  "_source": ["fieldA","fieldB"], 
  "size": 500, 
  "query": {
    "bool": {
      "should": [
        {"match": {
          "fieldA": valueA
        }},
        {"match": {
          "fieldB": "valueB"
        }
        }
      ]
    }
  }
}

```

But there are times where fieldB results get a higher score than fieldA results. So I'm trying to figure out where and how to put boosts. The docs only have the boosts after the entire boolean query, so if I want to adjust the score, do I need to do the following?

```auto
GET index/_search
{
  "_source": ["fieldA","fieldB"], 
  "size": 500, 
  "query": {
    "bool": {
      "should": [
        {"match": {
          "fieldA": valueA
        }}
      ],
     "should": [   
     {"match": {
          "fieldB": "valueB"
        }
        },
     < where do I add a boost? >
      ]
    }
  }
}

```

Thanks

---

<div class="post-metadata">

### Author: ![RabBit\_BR](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/rabbit_br/32/82261_2.png) [@RabBit\_BR](https://discuss.elastic.co/u/RabBit_BR)
#### Post date: [July 6, 2023, 8:44pm UTC](https://discuss.elastic.co/t/help-understanding-boolean-query-and-boosting/337842/2 "2023-07-06T20:44:29Z")

</div>

Hi @reswob

Try this:

```auto
{
  "_source": [
    "fieldA",
    "fieldB"
  ],
  "size": 500,
  "query": {
    "bool": {
      "minimum_should_match": 1, 
      "should": [
        {
          "match": {
            "fieldA": {
              "query": "valueA",
              "boost": 1 <----
            }
          }
        },
        {
          "match": {
            "fieldB": {
              "query": "valueB",
              "boost": 10 <----
            }
          }
        }
      ]
    }
  }
}

```

---

<div class="post-metadata">

### Author: ![reswob](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/reswob/32/38015_2.png) [@reswob](https://discuss.elastic.co/u/reswob)
#### Post date: [July 6, 2023, 9:22pm UTC](https://discuss.elastic.co/t/help-understanding-boolean-query-and-boosting/337842/3 "2023-07-06T21:22:52Z")

</div>

That worked great! Marked as solution.

Thanks.

---

<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: [August 3, 2023, 9:23pm UTC](https://discuss.elastic.co/t/help-understanding-boolean-query-and-boosting/337842/4 "2023-08-03T21:23:51Z")

</div>

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