-
Notifications
You must be signed in to change notification settings - Fork 218
Description
Is your feature request related to a problem?
The OpenSearch Search API supports an include_named_queries_score parameter (introduced in OpenSearch 3.0 and backported to 2.x). When enabled, the matched_queries field in the response changes from a List<String> to a Map<String, Double>.
The Java client currently has no way to request this parameter, nor does Hit.java have a field to store the resulting scores. Furthermore, because Hit.matched_queries is strictly typed as List<String>, enabling this parameter manually via a raw request throws deserialization errors.
What solution would you like?
I would like to add support for requesting and accessing these scores without breaking backward compatibility for existing users.
The solution should:
- Enable setting the
include_named_queries_scoreURL parameter. - Enable setting the
include_named_queries_scorerequest body attribute. - Add a new property to
Hit.java:@Nullable Map<String, Double> matched_query_scores.
Implementation Note:
To maintain backward compatibility, the deserialization logic for Hit will need to handle the polymorphic nature of the matched_queries JSON field:
- If JSON is
List<String>: Populate existingmatched_querieslist;matched_query_scoresremains null. - If JSON is
Map<String, Double>: Populate the newmatched_query_scoresmap AND populate the existingmatched_querieslist using the map keys. This ensures legacy code relying on the List continues to work seamlessly.
What alternatives have you considered?
[Breaking change] Change matched_queries to Map<String, Double>
The cleanest API solution would be to change the type of the existing field. However, Hit.matched_queries is currently exposed as a List<String>. Changing this would break binary and source compatibility for all users, which is likely unacceptable outside of a major version release.
Wrapper class
I considered introducing a wrapper class (e.g., MatchedQueries) to encapsulate the polymorphism. However, replacing the existing List<String> field with this wrapper is also a breaking change (same as above). Introducing a wrapper alongside the existing list seems overly complex compared to simply adding a Map field.
Do you have any additional context?
- OpenSearch server support added in: add support for scored named queries OpenSearch#11626
- Related discussion in
elasticsearch-java(where they opted for a breaking change in a new major version): Supportinclude_named_queries_scorein search requests elastic/elasticsearch-java#634
Given that OpenSearch 3.0 was released recently, waiting for a new major version of the client to introduce this feature seems undesirable. The proposed additive solution allows immediate support.