Mandeep Singh
Mandeep Singh

Reputation: 8224

elasticsearch: boost query based on values of a variable

I understand how to boost query in elasticsearch depending on absolute value of a variable. For example

{
    "query": {
        "bool": [
            { "match": {"field1": {"query": 10, "boost": 2}} }
        ]
    }
}

What I need to do is to make sure the field1 influences the score but I dont know any absolute value. For example, document will field1 = 20 will get higher score as compared to document with field1 = 10. However, this is different from sort. Because sorting is absolute. I just want this variable to contribute to the overall score but this is not the only field controlling the overall score.

Upvotes: 1

Views: 587

Answers (1)

Vineeth Mohan
Vineeth Mohan

Reputation: 19253

The best solution here would be function_score query It can be seen as the swiss army knife for customizing scores. You can use field_value_factor function in it to achieve what you are looking for.

Upvotes: 1

Related Questions