Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature request: sorting using the output of multiple script scores #3715

Closed
jayaddison opened this issue Jun 27, 2022 · 2 comments
Closed
Labels
enhancement Enhancement or improvement to existing feature or request feature New feature or request Indexing & Search

Comments

@jayaddison
Copy link

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 elasticsearch and opensearch - 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.

@jayaddison jayaddison added enhancement Enhancement or improvement to existing feature or request untriaged labels Jun 27, 2022
@andrross andrross added the feature New feature or request label Jul 8, 2022
@jayaddison
Copy link
Author

I think this can be closed; there doesn't seem to be supporting demand from any others for this feature, and also from some recent reading of the documentation, it seems to me that derived fields (available in v2.15+) may be able to satisfy this use-case.

@jayaddison jayaddison closed this as not planned Won't fix, can't repro, duplicate, stale Aug 24, 2024
@jayaddison
Copy link
Author

I think this can be closed; there doesn't seem to be supporting demand from any others for this feature, and also from some recent reading of the documentation, it seems to me that derived fields (available in v2.15+) may be able to satisfy this use-case.

Derived fields nearly provide the required functionality; openculinary/api#121 explores this and finds that scoring/sorting support for derived fields may also be required. There's no urgency for this feature, so I'll follow progress on those in the background.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Enhancement or improvement to existing feature or request feature New feature or request Indexing & Search
Projects
None yet
Development

No branches or pull requests

3 participants