Struct elastic::client::Client
[−]
[src]
pub struct Client { /* fields omitted */ }
A HTTP client for the Elasticsearch REST API.
The Client
is a structure that lets you create and send RequestBuilder
s.
It's mostly a thin wrapper over a reqwest::Client
.
Methods
impl Client
[src]
fn new(params: RequestParams) -> Result<Self>
Create a new client for the given parameters.
The parameters given here are used as the defaults for any
request made by this client, but can be overriden on a
per-request basis.
This method can return a HttpError
if the underlying reqwest::Client
fails to create.
Examples
Create a Client
with default parameters:
let client = Client::new(RequestParams::default()).unwrap();
Create a Client
for a specific node:
let client = Client::new(RequestParams::new("http://eshost:9200")).unwrap();
See RequestParams
for more configuration options.
fn request<'a, I>(&'a self, req: I) -> RequestBuilder<'a, I> where I: Into<HttpRequest<'static>>
Create a RequestBuilder
that can be configured before sending.
The request
method accepts any type that can be converted into
a HttpRequest<'static>
,
which includes the endpoint types in the requests
module.
Examples
Turn a concrete request into a RequestBuilder
:
// `PingRequest` implements `Into<HttpRequest>` let req = PingRequest::new(); // Turn the `PingRequest` into a `RequestBuilder` let builder = client.request(req); // Send the `RequestBuilder` let res = builder.send().unwrap();