I am currently trying to implement a "function_score" query in NEST, with functions that are only applied when a filter matches.
It doesn't look like FunctionScoreFunctionsDescriptor supports adding a filter yet. Is this functionality going to be added any time soon?
Here's a super basic example of what I'd like to be able to implement:
- Runs an ES query, with basic scores
- Goes through a list of functions, and adds to it the first score where the filter matches
"function_score": {
"query": {...}, // base ES query
"functions": [
{
"filter": {...},
"script_score": {"script": "25"}
},
{
"filter": {...},
"script_score": {"script": "15"}
}
],
"score_mode": "first", // take the first script_score where the filter matches
"boost_mode": "sum" // and add this to the base ES query score
}
I am currently using Elasticsearch v1.1.0, and NEST v1.0.0-beta1 prerelease.
Thanks!
It's already implemented:
The Udi's answer didn't work for me. It seems that in new version (v 2.3, C#) there's no Filter() method on
ScoreFunctionsDescriptor
class.But I found a solution. You can provide an array of
IScoreFunction
. To do that you can usenew FunctionScoreFunction()
or use my helper class:With this class, filter can be applied this way (this is just an example):