What if you could make search results smarter by mixing relevance with your own rules in one simple step?
Why Function score query in Elasticsearch? - Purpose & Use Cases
Imagine you have a huge list of products and you want to find the best ones based on both how well they match a search word and how popular they are. Doing this by hand means searching, then sorting by popularity separately, and trying to combine results yourself.
This manual way is slow and tricky. You might miss some good products because you can't easily mix search quality and popularity scores. It's like trying to pick the best apples by looking at color first, then weight, but not both together smoothly.
The function score query lets you mix the search match score with other factors like popularity in one step. It automatically adjusts scores so the best results consider both what you searched for and extra qualities you care about.
{ "query": { "match": { "name": "phone" } } }
// Then sort results by popularity separately{ "query": { "function_score": {
"query": { "match": { "name": "phone" } },
"field_value_factor": { "field": "popularity" }
} } }You can easily find results that balance relevance and custom factors, making searches smarter and more useful.
In an online store, customers search for "phone" and get results that not only match the word but also show popular and highly rated phones first.
Manual searching and sorting is slow and incomplete.
Function score query combines search relevance with custom scoring.
This makes search results smarter and more tailored.