[−][src]Struct elastic::client::Client
A HTTP client for the Elasticsearch REST API.
The Client
is a structure that lets you create and send request builders.
Client
is generic over a Sender
, but rather than use Client
directly, use one of:
Examples
Create a synchronous Client
and send a ping request:
let client = SyncClientBuilder::new().build()?; let response = client.request(PingRequest::new()) .send()? .into_response::<PingResponse>()?;
Create an asynchronous Client
and send a ping request:
let client = AsyncClientBuilder::new().build()?; let response_future = client.request(PingRequest::new()) .send() .and_then(|res| res.into_response::<PingResponse>()); tokio::runtime::current_thread::block_on_all(response_future)?;
Methods
impl<TSender> Client<TSender> where
TSender: Sender,
[src]
TSender: Sender,
pub fn request<TEndpoint, TBody>(
&self,
endpoint: TEndpoint
) -> RawRequestBuilder<TSender, TEndpoint, TBody> where
TEndpoint: Into<Endpoint<'static, TBody>>,
TBody: Into<TSender::Body>,
[src]
&self,
endpoint: TEndpoint
) -> RawRequestBuilder<TSender, TEndpoint, TBody> where
TEndpoint: Into<Endpoint<'static, TBody>>,
TBody: Into<TSender::Body>,
Create a RawRequestBuilder
with this Client
that can be configured before sending.
The request
method accepts any type that can be converted into a Endpoint<'static>
,
which includes the endpoint types in the endpoints
module.
Examples
Send a cluster ping and read the returned metadata:
// `PingRequest` implements `Into<Endpoint>` let req = PingRequest::new(); // Turn the `PingRequest` into a `RequestBuilder` let builder = client.request(req); // Send the `RequestBuilder` and parse as a `PingResponse` let ping = builder.send()?.into_response::<PingResponse>()?; println!("cluster: {}", ping.name());
impl<TSender> Client<TSender> where
TSender: Sender,
[src]
TSender: Sender,
pub fn search<TDocument>(
&self
) -> SearchRequestBuilder<TSender, TDocument, DefaultBody> where
TDocument: DeserializeOwned,
[src]
&self
) -> SearchRequestBuilder<TSender, TDocument, DefaultBody> where
TDocument: DeserializeOwned,
Create a SearchRequestBuilder
with this Client
that can be configured before sending.
For more details, see:
Examples
Run a simple Query String query for a DocumentType
called MyType
:
let query = "a query string"; let response = client.search::<MyType>() .index("myindex") .body(json!({ "query": { "query_string": { "query": query } } })) .send()?; // Iterate through the hits (of type `MyType`) for hit in response.hits() { println!("{:?}", hit); }
For more details on document types and mapping, see the types
module.
It's also possible to use serde_json::Value
s as documents when searching:
let response = client.search::<Value>() .index("myindex") .ty("my-type") .send()?;
impl<TSender> Client<TSender> where
TSender: Sender,
[src]
TSender: Sender,
pub fn bulk(&self) -> BulkRequestBuilder<TSender, Vec<u8>, BulkResponse>
[src]
Create a BulkRequestBuilder
with this Client
that can be configured before sending.
For more details, see:
Examples
Send a bulk request to index some documents:
let ops = (0..1000) .into_iter() .map(|i| bulk::<MyType>().index(MyType { id: i.to_string(), title: "some string value".to_owned() }) .id(i)); let response = client.bulk() .index("myindex") .ty(MyType::static_ty()) .extend(ops) .send()?; for op in response { match op { Ok(op) => println!("ok: {:?}", op), Err(op) => println!("err: {:?}", op), } }
impl Client<AsyncSender>
[src]
pub fn bulk_stream<TDocument>(
&self
) -> BulkRequestBuilder<AsyncSender, Streamed<TDocument>, BulkResponse>
[src]
&self
) -> BulkRequestBuilder<AsyncSender, Streamed<TDocument>, BulkResponse>
Create a BulkRequestBuilder
with this Client
that can be configured before sending.
This method can configure a channel that individual bulk operations can be sent to. The operations will be batched and debounced in the backgroun rather than being sent immediately.
For more details, see:
- [builder methods][builder-methods]
- [stream builder methods][stream-builder-methods]
- [send synchronously][send-sync]
- [send asynchronously][send-async]
Examples
Stream a bulk request to index some documents:
let (bulk_stream, bulk_responses) = client.bulk_stream() .index("bulk_idx") .ty(MyType::static_ty()) .timeout(Duration::from_secs(5)) .body_size_bytes(1024) .build(); let ops = (0..1000) .into_iter() .map(|i| bulk::<MyType>().index(MyType { id: i.to_string(), title: "some string value".into() }) .id(i)); let req_future = bulk_stream.send_all(futures::stream::iter_ok(ops)); let res_future = bulk_responses.for_each(|bulk| { println!("response:"); for op in bulk { match op { Ok(op) => println!(" ok: {:?}", op), Err(op) => println!(" err: {:?}", op), } } Ok(()) });
[builder-methods]: requests/bulk/type.BulkRequestBuilder.html#stream-builder-methods
[send-sync]: requests/bulk/type.BulkRequestBuilder.html#send-synchronously
[send-async]: requests/bulk/type.BulkRequestBuilder.html#send-asynchronously
[types-mod]: ../../types/index.html
[documents-mod]: ../../types/document/index.html
[docs-querystring]: https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-query-string-query.html
impl<TSender> Client<TSender> where
TSender: Sender,
[src]
TSender: Sender,
pub fn ping(&self) -> PingRequestBuilder<TSender>
[src]
Create a PingRequestBuilder
with this Client
that can be configured before sending.
For more details, see:
Examples
Ping an Elasticsearch node.
let response = client.ping().send()?; println!("node: {}", response.name());
impl<TSender> Client<TSender> where
TSender: Sender,
[src]
TSender: Sender,
pub fn document<TDocument>(&self) -> DocumentClient<TSender, TDocument>
[src]
Get a client for working with specific document type.
The document type can provide extra metadata like index and type names that can be used to simplify other API methods.
pub fn index(&self, index: impl Into<Index<'static>>) -> IndexClient<TSender>
[src]
Get a client for working with a specific index.
Trait Implementations
Auto Trait Implementations
impl<TSender> Send for Client<TSender> where
TSender: Send,
TSender: Send,
impl<TSender> Sync for Client<TSender> where
TSender: Sync,
TSender: Sync,
Blanket Implementations
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
impl<T, U> Into for T where
U: From<T>,
[src]
U: From<T>,
impl<T> From for T
[src]
impl<T, U> TryFrom for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = !
try_from
)The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T> Borrow for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> BorrowMut for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T, U> TryInto for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
try_from
)The type returned in the event of a conversion error.
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
impl<T> Same for T
type Output = T
Should always be Self
impl<SS, SP> SupersetOf for SP where
SS: SubsetOf<SP>,
SS: SubsetOf<SP>,