0

I want to search for a phrase to Elasticsearch like "personal tax date". I want the returned results to give more weight to the term "tax".

So far I know how to boost entire index or boost for different fields but still don't know how to boost different terms? Any help??

2 Answers 2

1

Using function score we can boost by fields

GET <index_name>/_search
{
    "query": {
        "function_score": {
           "query": {
            "query_string": {
               "query": "*personal tax date*",
               "fields": [
                "field_1",
                "field_2"
               ]
            }
            },
            "boost": "5",
               "functions": [
                          {
                  "filter": { "match": { "field": "tax" } },
                  "weight": 30
              },
              {
                  "filter": { "term": { "ent_name": "tax" } },
                  "weight": 25
              }
          ],
             "score_mode": "multiply",
            "boost_mode": "sum"
        }
    }
Sign up to request clarification or add additional context in comments.

Comments

1

You can use query_string query and boost the term using query string syntax as below:

{
  "query": {
    "query_string": {
      "query": "personal tax^2 date"
    }
  }
}

2 Comments

how can I multiply a term's importance by a floating number?
tax^2 here the boost value can be any floating value. Or use function score to modify the score calculated by elastic

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.