# Getting an error when using boost for multiple fields

**URL:** <https://discuss.elastic.co/t/getting-an-error-when-using-boost-for-multiple-fields/186187>\
**Category:** Elasticsearch\
**Created:** [June 18, 2019, 6:10am UTC](https://discuss.elastic.co/t/getting-an-error-when-using-boost-for-multiple-fields/186187 "2019-06-18T06:10:08Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![pyerunka](https://avatars.discourse-cdn.com/v4/letter/p/d6d6ee/32.png) [@pyerunka](https://discuss.elastic.co/u/pyerunka)\
**Post date:** [June 18, 2019, 6:10am UTC](https://discuss.elastic.co/t/getting-an-error-when-using-boost-for-multiple-fields/186187/1 "2019-06-18T06:10:08Z")

</div>

Hello,

When i am trying to add boost for multiple queries :  
POST /new\_master\_query/\_search  
{  
"query": {  
"match" : {  
"title": {  
"query": "test",  
"boost": 2  
},  
"object\_summary":{  
"query":"Test",  
"boost": 1  
}  
}  
}  
}

but i am getting an error:  
"error": {  
"root\_cause": [  
{  
"type": "parsing\_exception",  
"reason": "[match] query doesn't support multiple fields, found [title] and [object\_summary]",  
"line": 8,  
"col": 30  
}

Kindly guide me on this.

Thanks,  
Priyanka

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [June 18, 2019, 6:30am UTC](https://discuss.elastic.co/t/getting-an-error-when-using-boost-for-multiple-fields/186187/2 "2019-06-18T06:30:05Z")

</div>

If the text you are searching for is the same, use `multi_match` query, if not use a `bool` query with a `must` array with all your `match` queries inside.

---

<div class="post-metadata">

**Author:** ![pyerunka](https://avatars.discourse-cdn.com/v4/letter/p/d6d6ee/32.png) [@pyerunka](https://discuss.elastic.co/u/pyerunka)\
**Post date:** [June 18, 2019, 7:09am UTC](https://discuss.elastic.co/t/getting-an-error-when-using-boost-for-multiple-fields/186187/3 "2019-06-18T07:09:00Z")

</div>

Hello @dadoonet,

Thanks for reply!!

Is it possible to apply boost on multiple fields without adding query parameter?  
if yes then how?

Regards,  
Priyanka

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [June 18, 2019, 8:10am UTC](https://discuss.elastic.co/t/getting-an-error-when-using-boost-for-multiple-fields/186187/4 "2019-06-18T08:10:01Z")

</div>

Yes. The [documentation](https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-multi-match-query.html) says it. In case you did not read it, here it is:

```auto
GET /_search
{
  "query": {
    "multi_match" : {
      "query" : "this is a test",
      "fields" : ["subject^3", "message"] 
    }
  }
}

```

---

<div class="post-metadata">

**Author:** ![pyerunka](https://avatars.discourse-cdn.com/v4/letter/p/d6d6ee/32.png) [@pyerunka](https://discuss.elastic.co/u/pyerunka)\
**Post date:** [June 18, 2019, 8:18am UTC](https://discuss.elastic.co/t/getting-an-error-when-using-boost-for-multiple-fields/186187/5 "2019-06-18T08:18:43Z")

</div>

Hello @dadoonet,

Thanks for reply!!!

I do not want to add query parameter. In above example query is present. I only want to add different boost to different fields. for example: for title, value for boost is 3, for object\_summary it is 2 and so on. Can this is possible?

Regards,  
Priyanka

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [June 18, 2019, 8:55am UTC](https://discuss.elastic.co/t/getting-an-error-when-using-boost-for-multiple-fields/186187/6 "2019-06-18T08:55:21Z")

</div>

I don't understand then. If you don't query for anything by not "adding the query", what do you want to search for????

A full example could help to understand.

---

<div class="post-metadata">

**Author:** ![pyerunka](https://avatars.discourse-cdn.com/v4/letter/p/d6d6ee/32.png) [@pyerunka](https://discuss.elastic.co/u/pyerunka)\
**Post date:** [June 18, 2019, 9:08am UTC](https://discuss.elastic.co/t/getting-an-error-when-using-boost-for-multiple-fields/186187/7 "2019-06-18T09:08:17Z")

</div>

Hello @dadoonet ,

My requirement is when user searches any term or word, depending upon boost number of fields it should display the results.

For example, if user searches for “Test” and title has boost value as 2 and object\_summary has boost value as 1, then according to boost number more weightage should be given to title (as it has max boost value). And user will get the proper results. That means it should first search in title field and then in object\_sumary.

Is this possible using boost? If not what exactly boost does?

Regards,

Priyanka

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [June 18, 2019, 10:15am UTC](https://discuss.elastic.co/t/getting-an-error-when-using-boost-for-multiple-fields/186187/8 "2019-06-18T10:15:40Z")

</div>

Yes. That's I think the example I gave.

If you still don't make it work, could you provide a full recreation script as described in [About the Elasticsearch category](https://discuss.elastic.co/t/about-the-elasticsearch-category/21). It will help to better understand what you are doing. Please, try to keep the example as simple as possible.

A full reproduction script will help readers to understand, reproduce and if needed fix your problem. It will also most likely help to get a faster answer.

---

<div class="post-metadata">

**Author:** ![pyerunka](https://avatars.discourse-cdn.com/v4/letter/p/d6d6ee/32.png) [@pyerunka](https://discuss.elastic.co/u/pyerunka)\
**Post date:** [June 18, 2019, 10:56am UTC](https://discuss.elastic.co/t/getting-an-error-when-using-boost-for-multiple-fields/186187/9 "2019-06-18T10:56:16Z")

</div>

Hello @dadoonet,

I am getting what you are trying to say. Still I have one doubt, in below example, I have used 2 fields “title" and "object\_summary and boost value is 2. So when user searches they will get results by applying boost value as 2 for both fields.

> GET new\_master\_query/\_search  
> {  
> "query": {  
> "multi\_match" : {  
> "query": "this is a test",  
> "fields": ["title", "object\_summary"] ,  
> "boost":2  
> }  
> }  
> }

What if I want to give boost value 2 to title and 1 to object\_summary? Or is it assumed that if we have provided multiple fields then boost value for title is 2 and object\_summary is 1?

Regards,  
Priyanka

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [June 18, 2019, 11:37am UTC](https://discuss.elastic.co/t/getting-an-error-when-using-boost-for-multiple-fields/186187/10 "2019-06-18T11:37:34Z")

</div>

If you just follow the example I gave and the documentation I linked to you'll see that you can write:

```auto
GET new_master_query/_search
{
  "query": {
    "multi_match" : {
      "query": "this is a test",
      "fields": ["title^2", "object_summary"] 
    }
  }
}

```

---

<div class="post-metadata">

**Author:** ![pyerunka](https://avatars.discourse-cdn.com/v4/letter/p/d6d6ee/32.png) [@pyerunka](https://discuss.elastic.co/u/pyerunka)\
**Post date:** [June 19, 2019, 5:53am UTC](https://discuss.elastic.co/t/getting-an-error-when-using-boost-for-multiple-fields/186187/11 "2019-06-19T05:53:34Z")

</div>

Hello @dadoonet ,

Thanks for your reply!!!

As mentioned in above example, 2 is representing boost value for title. And that means when any user searches , first it will give preference to title and then to object \_summary and will show the results. Correct me if I am wrong.

Regards,  
Priyanka

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [June 19, 2019, 2:21pm UTC](https://discuss.elastic.co/t/getting-an-error-when-using-boost-for-multiple-fields/186187/12 "2019-06-19T14:21:18Z")

</div>

This is correct. More or less.  
It will multiply by 2 the score computed for title.

---

<div class="post-metadata">

**Author:** ![pyerunka](https://avatars.discourse-cdn.com/v4/letter/p/d6d6ee/32.png) [@pyerunka](https://discuss.elastic.co/u/pyerunka)\
**Post date:** [June 20, 2019, 5:05am UTC](https://discuss.elastic.co/t/getting-an-error-when-using-boost-for-multiple-fields/186187/13 "2019-06-20T05:05:10Z")

</div>

Hello @dadoonet,

Thanks for your reply!!!

What if I have used boost as 3? Please refer below example for the same. In that I have used segmentname^3.

> GET new\_master\_query/\_search  
> {  
> "query": {  
> "multi\_match" : {  
> "query": "Geosolutions",  
> "fields": ["segmentname^3", "object\_summary^2","title"] }  
> }  
> }

Regards,  
Priyanka

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [June 20, 2019, 5:41am UTC](https://discuss.elastic.co/t/getting-an-error-when-using-boost-for-multiple-fields/186187/14 "2019-06-20T05:41:59Z")

</div>

Yes.

---

<div class="post-metadata">

**Author:** ![pyerunka](https://avatars.discourse-cdn.com/v4/letter/p/d6d6ee/32.png) [@pyerunka](https://discuss.elastic.co/u/pyerunka)\
**Post date:** [June 20, 2019, 6:29am UTC](https://discuss.elastic.co/t/getting-an-error-when-using-boost-for-multiple-fields/186187/15 "2019-06-20T06:29:37Z")

</div>

Hello @dadoonet ,

Thanks for your reply!!!

I have used segmentname^3. After running it score is doubling. It should be thrice? Correct me if I am wrong.

Thanks,  
Priyanka

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [June 20, 2019, 6:45am UTC](https://discuss.elastic.co/t/getting-an-error-when-using-boost-for-multiple-fields/186187/16 "2019-06-20T06:45:35Z")

</div>

Try this:

```auto
GET /_search
{
  "query": {
    "multi_match" : {
      "query": "Geosolutions",
      "type": "most_fields",
      "fields": ["segmentname^3", "object_summary^2","title"]
    }
  }
}

```

Note that the boost is computed per field.  
If you need more details about how the score is computed add `explain: true`: [https://www.elastic.co/guide/en/elasticsearch/reference/7.1/search-request-explain.html](https://www.elastic.co/guide/en/elasticsearch/reference/7.1/search-request-explain.html)

---

<div class="post-metadata">

**Author:** ![pyerunka](https://avatars.discourse-cdn.com/v4/letter/p/d6d6ee/32.png) [@pyerunka](https://discuss.elastic.co/u/pyerunka)\
**Post date:** [June 20, 2019, 7:00am UTC](https://discuss.elastic.co/t/getting-an-error-when-using-boost-for-multiple-fields/186187/17 "2019-06-20T07:00:10Z")

</div>

Hello @dadoonet ,

Great!!! Thank you so much!!

Is there any relevancy used other than boost and Score in ES?

Thanks,  
Priyanka

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [June 20, 2019, 7:32am UTC](https://discuss.elastic.co/t/getting-an-error-when-using-boost-for-multiple-fields/186187/18 "2019-06-20T07:32:21Z")

</div>

Not sure I got the question but may be you want this? [https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-script-score-query.html](https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-script-score-query.html)

---

<div class="post-metadata">

**Author:** ![pyerunka](https://avatars.discourse-cdn.com/v4/letter/p/d6d6ee/32.png) [@pyerunka](https://discuss.elastic.co/u/pyerunka)\
**Post date:** [June 20, 2019, 9:13am UTC](https://discuss.elastic.co/t/getting-an-error-when-using-boost-for-multiple-fields/186187/19 "2019-06-20T09:13:17Z")

</div>

Hello @dadoonet,

I don’t want to change the score of the document. Actually I want to apply relevancy to my indexes so that user will get better results.

Thanks,  
Priyanka

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [June 20, 2019, 9:31am UTC](https://discuss.elastic.co/t/getting-an-error-when-using-boost-for-multiple-fields/186187/20 "2019-06-20T09:31:33Z")

</div>

So relevancy is based on score computation nowadays. But may be this as well can help: [https://www.elastic.co/guide/en/elasticsearch/reference/7.1/query-dsl-rank-feature-query.html](https://www.elastic.co/guide/en/elasticsearch/reference/7.1/query-dsl-rank-feature-query.html) (I never used it yet).

[Next page](https://discuss.elastic.co/t/getting-an-error-when-using-boost-for-multiple-fields/186187.md?page=2)
