-
Notifications
You must be signed in to change notification settings - Fork 190
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] Enable Generic HTTP Actions in Java Client #377
Comments
@RLashofRegas I agree with your request. I need something similar to this for the hadoop client. We need generic request and response classes for that would match |
@reta would love your feedback on this as well as opensearch-project/opensearch-hadoop#124 |
My apologies @harshavamsi , I am on vacation at the moment, should be back at the end of upcoming week |
This is a useful feature! |
@harshavamsi I would agree with you and @dblock that it could be a useful feature, but I would suggest to approach it from the perspective of generic client (as a child client), something along these lines:
The |
@reta What's the reason you prefer to prevent users from making arbitrary requests? In other clients I've seen such as Ruby all API calls are implemented as wrappers of generic HTTP methods, which seems to be appreciated by folks asking for this kind of feature. Maybe we can do the opposite, extract |
@dblock the
The users could make any arbitrary requests by just using However if you look into
My suggestion was to offer the generic client following such conventions, hope it makes sense. |
One other use case is for ISM APIs: https://opensearch.org/docs/latest/im-plugin/ism/api/. We need the generic HTTP actions and requests to support that |
I like this idea @reta. Let me put together a PR that adds this generic client. |
This sounds like a good idea. If I understand correctly we'd have a new interface to use which looks somewhat like the following?
It might be good to look at existing frameworks like HttpClient, WebClient, and RestTemplate. |
Hi @reta, in this implementation how do we de-serialize the response object without knowing the fields in the response? For example, the GetResponse class uses |
Hey @harshavamsi , since the client is generic, the requests and responses are also generic: the consumer would need to deserialize the response body (the same goes with request body serialization) to whatever it thinks it should be. |
@harshavamsi ElasticSearch already provides a low-level REST client with a generic |
@RLashofRegas we cannot accept/look at non-open-source code. Please feel free to reimplement something similar without copying code that's not-APLv2-compatible. |
@dblock I think it falls into "use raw transport" alternative (from description):
The OpenSearchTransport exposes performRequest() to do raw requests |
Ah yes! Someone write a sample :) |
Other REST frameworks such as Spring's RestTemplate and WebClient support this by having the call provide the class to serialize to. Take
The framework will deserialize into the
As it appears the |
@dlvenable the problem with that is that these frameworks (with this approach) do not provide the access to response status code etc - the developers have to deal with tons of exceptions. This functionality could be provided by base
Since this is generic client, providing access to underlying response details is a must (I think). |
That is still possible. RestTemplate actually allows for the response to come as a When you use it this way, you do not get exceptions. |
I think we should keep API as minimal as possible: this is not a generic HTTP based client. |
I created a proof-of-concept for using the Transport to perform a request. It is definitely not straightforward, mostly because of the deserialization of the response. I ended up copying and pasting some code from opensearch-java because it is package protected. You can see it all in this one file. (It's a branch of data-prepper, but just look at the one file). |
@dlvenable There is a pull request already [1], would be good to consolidate efforts there [1] #415 |
This is something that my team have also had to work around, and would appreciate a solution for. We migrated from elasticsearch, which as someone stated above, does support such requests. |
i also need this in order to implement |
#257 is related. |
@VachaShah @dblock @dlvenable mind if I pick this issue up, that would help to unblock the dedicated support of the OpenSearch in Liquibase @rursprung is working on. Thanks folks. |
All yours @reta! |
Hello, |
Is your feature request related to a problem?
Not all requests I need to make to OpenSearch are supported natively by the client. One example is mapping AWS IAM Roles to FGAC roles in the security plug-in. These require doing a post request to the
_plugins/_security
endpoint. Since the client doesn't natively support the_plugins
endpoint I need to send a genericPUT
request. Right now the client has generic APIs forget(...)
anddelete(...)
(NOTE: as I'm looking back at theget
API even that seems to only support getting documents not genericGET
...), but it does not have the same forput(...)
orpost(...)
. These are needed to make it easy for clients to use the OpenSearch client to send all the requests they need to make to the cluster with a single client interface.What solution would you like?
Add
PutResponse put(PutRequest request)
andPostResponse post(PostRequest request)
to theOpenSearchClient
API.What alternatives have you considered?
Right now it seems the only alternative would be to manually create a
PutRequest
class and pass this directly totransport.performRequest(...)
similar to what is done for thedelete(...)
API here.Do you have any additional context?
No.
The text was updated successfully, but these errors were encountered: