Steven Z.
Steven Z.

Reputation: 67

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.

Upvotes: 3

Views: 2484

Answers (1)

Jaycreation
Jaycreation

Reputation: 2089

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

Upvotes: 6

Related Questions