Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Elastic Search set field weight for a individual search

I'm very new to elastic search, say in my document I have fields A, B, C, D, and I want to search the word "test" in all fields.

I want each field to have different weights, (ie. A has 10, B has 8, C has 5, and D has 2). How do I write a es query to perform that on the word I'm searching.

like image 903
Steven Z. Avatar asked Nov 26 '25 09:11

Steven Z.


1 Answers

It's a classical use case. The most easy way is to use a multi-match query with boosters. In a multimatch add ^boostvalue to the field name to apply a boost on it

GET test/_search
{
  "query": {
    "multi_match": {
      "query": "test",
      "fields": ["A^10", "B^5", "C^2"]
    }
  }
}
like image 112
Jaycreation Avatar answered Nov 28 '25 15:11

Jaycreation



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!