-
Notifications
You must be signed in to change notification settings - Fork 2.5k
[Feature Request] Surface named rescore queries in matched_queries #18665
Description
Is your feature request related to a problem? Please describe
OpenSearch supports naming query clauses using _name, and reports matched clause names (along with the score if include_named_queries_score is set to true) in the matched_queries array of search hits. This is incredibly helpful for debugging, logging query signals, or building ML models that rely on signal-level match information.
However, when a _name is specified inside a rescore.query.rescore_query, that name is not surfaced in matched_queries - even if it clearly matched and impacted the final score. This makes it difficult to trace which rescore clause contributed to ranking and what the calculated score was.
This behavior is also inconsistent with Elasticsearch, which does support named queries inside rescore and includes them in matched_queries.
Describe the solution you'd like
I would like a solution which extends support to also propagate _name values and scores from rescore_query clauses into the matched_queries array, just like it does for regular query clauses. That way, we can tell whether a document was matched overall, and also identify which specific part of the rescore logic contributed to its ranking and by how much.
Related component
Search:Query Capabilities
Describe alternatives you've considered
One workaround I have considered is to duplicate the rescore clause into the main query using a should clause with very low boost and _name. However, this clutters the query, adds performance overhead, and distorts scoring behavior.
Another option is to re-run the rescore query logic outside of OpenSearch as a post-processing step, but that defeats the purpose of having first-class rescore support.
Additional context
Example:
PUT /rescore_test
{
"mappings": {
"properties": {
"headline": { "type": "text" },
"summary": { "type": "text" }
}
}
}
POST /rescore_test/_doc/1
{
"headline": "OpenSearch rescore behavior",
"summary": "This document illustrates how rescore affects scoring but not matched_queries."
}
GET /rescore_test/_search
{
"query": {
"match": {
"headline": {
"query": "rescore behavior",
"_name": "headline_match"
}
}
},
"rescore": {
"window_size": 50,
"query": {
"rescore_query": {
"match_phrase": {
"summary": {
"query": "rescore affects scoring",
"_name": "summary_phrase_match"
}
}
}
}
}
}
Expected matched_queries:
["headline_match", "summary_phrase_match"]
Actual matched_queries:
["headline_match"]
Metadata
Metadata
Assignees
Labels
Type
Projects
Status