# How to boost results on the basis of fields values

**URL:** https://discuss.elastic.co/t/how-to-boost-results-on-the-basis-of-fields-values/287826
**Category:** Elasticsearch
**Created:** [October 27, 2021, 4:10pm UTC](https://discuss.elastic.co/t/how-to-boost-results-on-the-basis-of-fields-values/287826 "2021-10-27T16:10:37Z")
**Posts on this page:** 9
**Page:** 1

<div class="post-metadata">

### Author: ![Ashutosh\_Dwivedi](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ashutosh_dwivedi/32/96413_2.png) [@Ashutosh\_Dwivedi](https://discuss.elastic.co/u/Ashutosh_Dwivedi)
#### Post date: [October 27, 2021, 4:10pm UTC](https://discuss.elastic.co/t/how-to-boost-results-on-the-basis-of-fields-values/287826/1 "2021-10-27T16:10:37Z")

</div>

Hi Everyone,  
I have stuck into creating query for a specific problem. Can anyone please help me ?  
I have these list of products

```auto
[
{
  "name":"pro",
  "clickCount":110,
  "bookingCount":57,
  "isPromoted":0
},
{
  "name":"prod",
  "clickCount":13,
  "bookingCount":77,
  "isPromoted":0
},
{
  "name":"produ",
  "clickCount":43,
  "bookingCount":10,
  "isPromoted":0
},
{
  "name":"produc",
  "clickCount":5,
  "bookingCount":17,
  "isPromoted":0
},
{
  "name":"product",
  "clickCount":89,
  "bookingCount":67,
  "isPromoted":0
},
{
  "name":"products",
  "clickCount":1,
  "bookingCount":2,
  "isPromoted":1
}
]

```

I need to rank these products into this manner:

- All the products having isPromoted should come at the top.
- After that, we need to rank them on the basis of sum of clickCount and bookingCount
- We need to take care of word matching too in this ranking. (Like for a search `pro` ), the product named pro should come first(because it matches fully), but should come after promoted products.

Will be really helpful, if someone can help me to formulate query

---

<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: [October 27, 2021, 4:25pm UTC](https://discuss.elastic.co/t/how-to-boost-results-on-the-basis-of-fields-values/287826/2 "2021-10-27T16:25:02Z")

</div>

Welcome.

I'd use multiple queries with a `should` array of a `bool` query.

Then I'd boost some of them, like the `term` query on the `isPromoted` field.

You could also look at [Rank feature query | Elasticsearch Guide [7.15] | Elastic](https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-rank-feature-query.html)

---

<div class="post-metadata">

### Author: ![Ashutosh\_Dwivedi](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ashutosh_dwivedi/32/96413_2.png) [@Ashutosh\_Dwivedi](https://discuss.elastic.co/u/Ashutosh_Dwivedi)
#### Post date: [October 27, 2021, 4:27pm UTC](https://discuss.elastic.co/t/how-to-boost-results-on-the-basis-of-fields-values/287826/3 "2021-10-27T16:27:42Z")

</div>

Can you please tell me how to do that?  
I am not able to formulate query  
I formulated this but couldn't include keyword search and its not working properly.

```auto
GET /products/_search
{
  "query": {
    
    "function_score": {
      "functions": [
        {
          "field_value_factor": {
            "field": "clickCount",
            "factor": 0.3,
            "modifier": "sqrt"
          }
        },
        {
          "field_value_factor": {
            "field": "bookingCount",
            "factor": 0.9,
            "modifier": "sqrt"
          }
        },
        {
          "field_value_factor": {
            "field": "isPromoted",
            "factor": 1.2,
            "modifier": "sqrt"
          }
        }
      ]
    }
  }
}

```

---

<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: [October 27, 2021, 4:52pm UTC](https://discuss.elastic.co/t/how-to-boost-results-on-the-basis-of-fields-values/287826/4 "2021-10-27T16:52:24Z")

</div>

As I wrote, use a bool query.

---

<div class="post-metadata">

### Author: ![Ashutosh\_Dwivedi](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ashutosh_dwivedi/32/96413_2.png) [@Ashutosh\_Dwivedi](https://discuss.elastic.co/u/Ashutosh_Dwivedi)
#### Post date: [October 27, 2021, 4:59pm UTC](https://discuss.elastic.co/t/how-to-boost-results-on-the-basis-of-fields-values/287826/5 "2021-10-27T16:59:55Z")

</div>

Can you please tell me how to combine those

---

<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: [October 27, 2021, 6:18pm UTC](https://discuss.elastic.co/t/how-to-boost-results-on-the-basis-of-fields-values/287826/6 "2021-10-27T18:18:26Z")

</div>

Add multiple clauses in a `should` array within a `bool` query.  
If you still don't understand have a look at this example:

> <https://gist.github.com/dadoonet/5179ee72ecbf08f12f53d4bda1b76bab>

---

<div class="post-metadata">

### Author: ![Ashutosh\_Dwivedi](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ashutosh_dwivedi/32/96413_2.png) [@Ashutosh\_Dwivedi](https://discuss.elastic.co/u/Ashutosh_Dwivedi)
#### Post date: [October 29, 2021, 6:39am UTC](https://discuss.elastic.co/t/how-to-boost-results-on-the-basis-of-fields-values/287826/7 "2021-10-29T06:39:33Z")

</div>

Hi @dadoonet ,  
Thank you for helping out.  
I am sorry, I am not able to comeup with any solution. can you please help

---

<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: [October 29, 2021, 1:10pm UTC](https://discuss.elastic.co/t/how-to-boost-results-on-the-basis-of-fields-values/287826/8 "2021-10-29T13:10:12Z")

</div>

What did you try so far? What did not work for you?

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 is something anyone can **copy and paste in Kibana dev console** , click on the run button to reproduce your use case. It 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: ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)
#### Post date: [November 26, 2021, 1:11pm UTC](https://discuss.elastic.co/t/how-to-boost-results-on-the-basis-of-fields-values/287826/9 "2021-11-26T13:11:02Z")

</div>

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