Closed Jon-AtAWS closed 11 months ago
This happens because without a leading slash the request is performed against the host called _ml/...
. Prefix the path with a /
.
resp = client.transport.perform_request(
"GET", "/_plugins/_ml/models/_search", body='{"query": {"match_all":{}}}'
)
I made a sample that creates an index and indexes a document in https://github.com/dblock/opensearch-python-client-demo/blob/main/sync/transport.py, that should get you started - feel free to add an ml.py
sample into that project and I can help you if you run into more problems.
Leaving this issue open. I think we want to expose transport.perform_request
as get
, put
, post
and delete
.
@Jon-AtAWS you should check out the github.com/opensearch-project/opensearch-py-ml client it has support for these API's. Generally, I agree though. We should provide a generic helper that allows users to run non-implemented API endpoints.
@dblock have you heard any discussion of rolling the ML client into this one? I know there was some talk about allowing different parts to be installed optionally with pip but I cant find that issue. If that was implemented it should make it a more straightforward move.
@dtaivpp - The py-ml client is in a state of flux right now, and doesn't support many of the operations I needed for my implementation. I ended up falling back to the requests library to manual those. Once I complete my example, I'll publish that somewhere and add a couple improvement ideas to the py-ml client.
Having said that, this request is more about a general way to send REST requests (per @dblock above as well). The Dev Tools tab from Dashboards makes it simple to send these requests. I'm looking for something like that in code.
@dblock have you heard any discussion of rolling the ML client into this one?
I have not. Maybe you want to open/find an existing issue? This client has been adding support for various plugins for a while.
I think we want to expose transport.perform_request as get, put, post and delete.
I am able to reuse the client.transport.perform_request
to send api request to KNN APIs which are not part of the client.
Like this
client.transport.perform_request('GET', f'/_plugins/_knn/warmup/{vector_index_name}', )
@dblock I think the feature is already there.
@dblock I think the feature is already there.
I think we still need a DSL, e.g. client.get
or client.http_get
or something like that, that is documented and tested explicitly. Right now perform_request
is undocumented and internal.
Oh yes.. documentation is required and not sure about what DSL means here.
domain specific language - I mean I'd like to write client.get
rather than client.transport.perform_request
.
@dblock can we do this for all the client in different languages. Every time some customer ask this I had to dig into the code to find out how to do such requests..
Absolutely.
I've opened an umbrella issue to collect this and similar requests across clients, https://github.com/opensearch-project/opensearch-clients/issues/62.
Is your feature request related to a problem?
I'm trying to list out loaded ml models via the python client (different feature request on that). The way to do that is to run a match_all query against _plugins/_ml/models. opensearchpy.search doesn't support setting the path like that. I need a clean way to send the request. More generally, I want something like the "requests" library that supports GET, PUT, POST, etc. by URL and body, but that backs out to the cluster with all of the auth, etc. from the client.
What alternatives have you considered?
Even if the below works, it would be nice to have opensearchpy.search support setting the path and body.
I tried:
But received
The equivalent call via the requests library works fine:
If this is the preferred method, then that needs to be in the documentation somewhere.