opensearch-project / opensearch-java

Java Client for OpenSearch
Apache License 2.0
115 stars 181 forks source link

[FEATURE] Need to access new index setting made available in serverless #589

Open dvjyothsna opened 1 year ago

dvjyothsna commented 1 year ago

Suppose someone were working on a new serverless api that adds a new read only setting to an index called x. What would be a good way for the opensearch java client to support users of serverless who wants to read the setting?

dblock commented 1 year ago

AFAIK it’s the same problem as wanting to support multiple versions of OpenSearch, with semver in mind. I see it work as follows.

At dev time, a custom schema for each version and flavor of server-side OpenSearch is consumed by the client. Each schema generates complete clients, e.g. opensearch.aoss.client.Client() will be generated from AOSS 2.3 schema, and opensearch.oss.client.Client() will be generated from OpenSearch 2.9 schema.

A sum of all schemas generates opensearch.client.Client(). Methods are annotated with all versions that they exist in, e.g. AOSS 2.3 and OS 2.9.

An intersection of all schemas generates opensearch.all.client.Client().

At runtime the generated code examines any response for server version on every response, so now it knows whether it's talking to AOSS 2.3 vs. OSS 2.9.

At runtime the generated code can check whether the method being called exists in the flavor being communicated with by comparing the annotations and produce warnings or errors.

For your example the setting being added exists in opensearch.aoss.client and opensearch.client, but not in opensearch.os.client. If I talk to OS with the setting via opensearch.client it fails loudly, and if I talk to AOSS it works.

WDYT?

wbeckler commented 1 year ago

I can think of a few approaches. One would be to allow for untyped responses to be parsed as json: https://github.com/opensearch-project/opensearch-java/issues/377