How to boost results on the basis of fields values

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

[
{
  "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

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

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.

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"
          }
        }
      ]
    }
  }
}

As I wrote, use a bool query.

Can you please tell me how to combine those

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

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

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. 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.

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