elastic / elasticsearch-rs

Official Elasticsearch Rust Client
https://www.elastic.co/guide/en/elasticsearch/client/rust-api/current/index.html
Apache License 2.0
695 stars 70 forks source link

[BUG] The send() method of Search always uses a POST request if the search has a body #197

Closed ppearson closed 2 years ago

ppearson commented 2 years ago

From looking at the code, for search, the Rust client seems to assume that if there's a body (i.e. a query for a search), then the POST method should be used:

let method = match self.body { Some(_) => Method::Post, None => Method::Get, };

However, ElasticSearch has long allowed GET methods with bodies: https://www.elastic.co/guide/en/elasticsearch/guide/current/_empty_search.html

in other words, search queries with GET requests but a message body. The Python API for example does seem to use GET requests for search queries with bodies.

And because of this, many servers are set up such that they only allow no-credential access for search and GET, and with the Rust client as it currently is, it's not possible to use these servers.

It would be nice if there could be some way to allow specifying the request method.

sethmlarson commented 2 years ago

Thanks for opening this issue. This is standard behavior across all Elasticsearch clients to decide the HTTP method based on whether there is a provided body or not. We test every client against Elasticsearch and haven't observed the issue you're experiencing with credential-less access and GET.

If you'd like more control over the HTTP method used for requests you can use the underlying HTTP library to accomplish this.