-
Notifications
You must be signed in to change notification settings - Fork 34
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] Make raw JSON REST requests to OpenSearch #193
Comments
@Xtansia , I'll like to pick this up. How do you suppose I go about this in a way that aligns with the long term vision of the project |
@samuelorji I would say a first step is to investigate and document what's already possible in this style in the client, for example we currently accept arbitrary JSON for all the defined endpoints, so maybe try to understand how one of the existing operations works. Then you can share your findings here in the issue, and determine an appropriate design that is similar to the existing ones, but allows setting an arbitrary path and http method etc. It should still use a similar "transport" call that the existing ones use like https://github.com/opensearch-project/opensearch-rs/blob/94e7b724b957259f4268151fe2d08dd5d2a3eb25/opensearch/src/root/mod.rs#L4385C5-L4438C6 |
It's already possible to do this with the rust client with use opensearch::OpenSearch;
use opensearch::http::headers::HeaderMap;
use opensearch::http::Method;
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let client = OpenSearch::default();
let body = b"{\"query\":{\"match_all\":{}}}";
let response = client
.send(
Method::Post,
"/_some_api_that_may_exist",
HeaderMap::new(),
None,
Some(body.as_ref()),
None
)
.await?;
let string_response = response.text().await?;
Ok(())
} This can send a raw request to any endpoint, and you can use the use opensearch::{OpenSearch, SearchParts};
use opensearch::http::headers::HeaderMap;
use opensearch::http::Method;
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let client = OpenSearch::default();
let body = b"{\"query\":{\"match_all\":{}}}";
let response = client
.send(
Method::Post,
SearchParts::Index(&["tweets"]).url().as_ref(),
HeaderMap::new(),
None,
Some(body.as_ref()),
None,
)
.await?;
Ok(())
} If you're wanting to support raw JSON strings for each concrete API builder that accepts JSON, the |
The first example is what I'm after (no specialized classes like |
Will add this to the user guide |
Closing via #196. |
@dblock Shouldn't this stay open as we want a cleaner high-level wrapper as well? |
I've been going back and forth. I think for this client it should be closed, |
Is your feature request related to a problem?
Coming from opensearch-project/opensearch-clients#62, add support for making raw JSON requests.
What solution would you like?
Add a high level DSL, e.g.
client.get
andclient.post
.The text was updated successfully, but these errors were encountered: