-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Description
Hello OpenSearchers 👋
As part of planning migration away from using function_score -- based on a sense from elastic/elasticsearch#42811 that it may be deprecated in future -- I'm looking for alternative query workflows to support search operations that involve a combination of script evaluation and sorting.
Background
The specific search use case is described here.
My explanation of the process: after matching documents are discovered, scoring is performed by evaluating a scoring script on them. The script emits a value that is a combination of two numeric calculations: a core "rank", and a subsequent "tiebreaker" that provides second-level sorting within groups of equally-ranked documents.
The only reason that function_score is used in the code is to replace the _score value on each document with the script's return value.
Feature Request
The feature request is to allow multiple scripts to be evaluated against matched documents, and to request sorting based on the output of those.
In other words: the feature would provide migration from a (pseudocode) query of the form:
run script {rank+tiebreaker} on each document => replace the {_score} with the {rank+tiebreaker} output => sort based on: {_score desc}
...to a query of the form:
run scripts [{rank}, {tiebreaker}] on each document => sort based on: [{rank desc}, {tiebreaker desc}]
Where the latter query form does not involve a function_score step.
Other considerations
- I realize that there could be architectural/design challenges implementing something like this - query request format does not necessarily correspond to query plan representation
- I'm not aware of other users with a similar request/requirement -- I have searched around for any in the issue tracker
- It seems like allowing multiple scripts to be evaluated could introduce potential performance risks (up-to-and-including denial-of-service concerns) -- although to some extent I think that risk already exists for any search appliance where script-eval per result is enabled
- Although it might be a bit strange/awkward, I think I'll open this feature request against both
elasticsearchandopensearch- it's not intended as a competition, I'm not running an academic study, I don't want to waste anyone's time, and I have no particular relationship with either project - I'm just not aware of a better way (currently?) to raise awareness of a feature request that could be relevant to both projects other than duplicating the feature request itself
Please let me know if there's any more information I can add or details that I can clarify.