"Inject" external value for sorting

Hello, thanks for your answer,
but i don't really understand how to add custom calculated field to the
document using custom_filters_scrore.

Could you please describe bit more about this?

On Tuesday, May 15, 2012 6:12:25 AM UTC+2, Narinder Kaur wrote:

You can try with the cusom_filters_score at :

http://www.elasticsearch.org/guide/reference/query-dsl/custom-filters-score-query.html

and you can assign the value to the document based on some specific field
value. I hope its very good solution for your problem, if implemented
properly.

On Monday, 14 May 2012 20:04:37 UTC+5:30, Vadim Voituk wrote:

Hello,

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
script").

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:

Redirecting to Google Groups

What is the right way to solve my problem?

Thanks in advance for any ideas, comments and suggestions.