Implementing boost factor on conditional query

Hi, I am new to elasticsearch.

I have document having values for employee, their department and salary. I want to apply boost factor based on department and their salary condition based i.e. salary less than 1500$ should get higher ranking. For example.

"Department" : "Technical",
"Boost": "2"
"Salary" : "<=1500",
"Boost":"1"

Expected output:

Name: ABC,
Department: Technical
Salary: 1000

Name: XYZ
Department: Technical
Salary: 1200

Name: PQR
Department: Technical
Salary: 1600

Please suggest how can I write this query in elastic.

Regards

You could probably use a bool query with should clauses and boost everyone on those closes.

Also function score API could help.

My 2 cents

I had tried using script_field for salary, but it was returning only true / false value; however I am looking for complete resultset, with name, department and salary as well

I have used bool query with should and must clause and boost factor on the required ones, however not sure how to take care the Salary part of the clause with the boost factor.

I dunno if you don't share a full reproduction script.

samle query script, as below,

GET employee/employeedetail/_search
{
"query": {
"function_score": {
"query":{
"filtered":{
"query":{
"bool":{
"must":[
{
"match":{
"department":{
"query":"technical"
}
}
}
],
"should": [
{
"term": {
"gender": {
"value": "male",
"boost": 2
}
}
}
]
}
}
}
},

  "functions": [
    
    {
      "gauss": {
        "salary": {
          "origin": "50",
          "offset": "50", 
          "scale": "10"
        }
      },
      "weight": 1
    },
    {
      "script_score": {
        "script": "_score * doc['salary'].value"
      }
    }
  ]
  
}

}

}