Open dbwiddis opened 1 month ago
As you've noted for cases like Operator
the JsonEnum
type does have an affordance for aliases for given enum values. So this should be an easy fix of just amending ZeroTermsQuery
to add the all-caps variants as aliases.
This is something we should consider how to represent in the spec: https://github.com/opensearch-project/opensearch-api-specification/blob/19421f502740967e4d6df102f1c5765c53eaa010/spec/schemas/_common.query_dsl.yaml#L943
This is something we should consider how to represent in the spec: https://github.com/opensearch-project/opensearch-api-specification/blob/19421f502740967e4d6df102f1c5765c53eaa010/spec/schemas/_common.query_dsl.yaml#L943
I love/hate regex. :)
I agree with you though, this should likely be handled in the spec somehow but not sure there's a standard for that and not sure we want to hand-edit exceptions. It's easy enough to work around if documented, but let's at least discuss options.
It looks like Jackson JsonP does support this with appropriate annotations. https://stackoverflow.com/questions/26058854/case-insensitive-json-to-pojo-mapping-without-changing-the-pojo
What is the bug?
The enum defined for the client uses lower case values for the
ZeroTermsQuery
enum: https://github.com/opensearch-project/opensearch-java/blob/08e7e6504d4e6029640940f4bb4670e5e183c700/java-client/src/main/java/org/opensearch/client/opensearch/_types/query_dsl/ZeroTermsQuery.java#L38-L42However, this enum is defined on OpenSearch with traditional all-caps enum names:
As a result, a search query generated on OpenSearch can not simply transform its JSON into a client search request.
How can one reproduce the bug?
SearchSourceBuilder
:SearchSourceBuilder
to JSON:Note the value of
zero_terms_query
is all upper case.SearchRequest
object:What is the expected behavior?
In general, an OpenSearch
SearchSourceBuilder
can be serialized into JSON and then deserialized into an OpenSearch Java ClientSearchRequest
.In this particular case, the all-caps enum name should match case-insensitively rather than throwing an exception.
See, for example, how logical operators (such as the
OR
in this query) accept either all-upper or all-lower case: https://github.com/opensearch-project/opensearch-java/blob/08e7e6504d4e6029640940f4bb4670e5e183c700/java-client/src/main/java/org/opensearch/client/opensearch/_types/query_dsl/Operator.java#L39-L42What is your host/environment?
Running this on OpenSearch 2.15 code, but it has not changed since pre-fork.
Do you have any additional context?
Relevant code block causing the issue on a feature branch: https://github.com/opensearch-project/ml-commons/blob/feature/multi_tenancy/plugin/src/main/java/org/opensearch/ml/sdkclient/RemoteClusterIndicesClient.java#L230-L232