The problem with custom_score is that it overwrites original score value
calculated by ES.
But i want my external "sorting value" to be available in a sorting formula
together with original score and etc.
Something like that
script: doc.score0.34123+ externalScore0.1232
Where float numbers are generated on client side (for example depending of
user settings), right before sending query to ES, but the "externalScore" -
it's my external value.
I've implemented this in a way like:
- I'm receiving the ranking formula from as an parameter to my native
- Injecting externalScore value to mvel scope
- Passing it to MvelScriptEngine for further processing
From client-side it looks like:
// ... some script specific params
script: doc.score0.34123+ externalScore0.1232 // just a string
param processed by mvel script engine
It works pretty fast, but i have a strong feeling that there are more
elegant way to do this.
Maybe some kind of plugin endpoint, i've missed?
On Thursday, May 17, 2012 10:29:49 PM UTC+2, kimchy wrote:
Sorry, but I did not understand the question..., script_fields are fields
that only affect the top N hits you return, not the whole doc set. You
probably want to have a script (can be native) that you then use with
On Mon, May 14, 2012 at 5:34 PM, Vadim Voituk wrote:
What i'm trying ot implement is an ES-plugin, that "inject" some kind of
external value (number) into document during search.
Then this value will should be used in a sorting expression ("sort
My plugin register a native script, that is used in "script_fields" to
create additional "virtual" field.
But the problem there, that "script_fields" are calculated on a
"returnable top" part of result-set.
So such type of fields can't be used as part of sorting criteria.
Also "injecting" in sort a script (that is OK for my particular case) not
works too, since doc(), source() and fields() return read-only collections.
Another one approach i'm thinking about is - to extend the mvel namespace
with own, custom-made function, that will return this "external" value, and
can be used in an sorting script like:
"script": " doc.score*2 + myCustomFunction(doc._id.value) "
But i can't find the proper way to extend mvel engine for now.
I've found a similar question but there are no solution published there:
What is the right way to solve my problem?
Thanks in advance for any ideas, comments and suggestions.