Boost score based on integer value - Elasticsearch
You are looking at function score query
: https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-function-score-query.html
And field value factor
https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-function-score-query.html#function-field-value-factor.
Snippet from documentation:
GET /_search{ "query": { "function_score": { "field_value_factor": { "field": "tags.dislikes", "factor": 1.2, "modifier": "sqrt", "missing": 1 } } }}
Or with script score
because your nested tags
field (not sure if field value score
works fine with nested structure).
This took a long time to figure out. I have learnt so much on my way there.
Here is the final result:
{ "query": { "nested": { "path": "tags", "query": { "function_score": { "query": { "bool": { "should": [ { "match": { "tags.name": "example" } }, { "match": { "tags.name": "testing" } }, { "match": { "tags.name": "test" } } ] } }, "functions": [ { "field_value_factor": { "field": "tags.votes" } } ], "boost_mode": "multiply" } } } }}
The array in should
has helped a lot, and was glad I could combine it with function_score