I am creating a custom script in Java for scoring documents. I am looking to try and get the document’s score prior to going into the custom scorer.
In mvel it seems that you can just do:
“_score * doc[‘my_numeric_field’].value / pow(param1, param2)”
and _score will just give you the score. I don’t see any effective way of getting the score with the Java API.
Note: I’ve tried doc().getScore() and that seems to always give a null pointer exception.
Bonus: How would I be able to get other document fields such as _boost or _index?
The native script equivalent of “_score * doc[‘my_numeric_field’].value / pow(param1, param2)” would be:
you can calculate
pow(param1, param2)in the factory method since it doesn’t change betweenrunAsFloat()executions.If
_indexfield is enabled, it can be accessed like this:I would recommend using query time boosting instead of index time boosting.