pub struct Client { /* private fields */ }Expand description
A connection to an OpenSearch cluster.
Cheap to clone (it shares one connection pool). Construct with
Client::connect, optionally adding credentials with
Client::basic_auth.
Implementations§
Source§impl Client
impl Client
Sourcepub fn connect(url: impl AsRef<str>) -> Result<Self>
pub fn connect(url: impl AsRef<str>) -> Result<Self>
Connect to the cluster at url (http or https). This validates the
URL and builds the HTTP client; it does not perform any I/O.
Sourcepub fn basic_auth(
self,
username: impl Into<String>,
password: impl Into<String>,
) -> Self
pub fn basic_auth( self, username: impl Into<String>, password: impl Into<String>, ) -> Self
Attach HTTP basic-auth credentials, applied to every request.
Sourcepub async fn get_one<T>(
&self,
index: &str,
hash: &str,
id: impl Display,
) -> Result<Option<T>>where
T: DeserializeOwned,
pub async fn get_one<T>(
&self,
index: &str,
hash: &str,
id: impl Display,
) -> Result<Option<T>>where
T: DeserializeOwned,
Fetch a single document by id from <index>_<hash>/_doc/<id>. Returns None
when the document does not exist.
Until the derive generates Type::get, callers invoke this directly with
the document type as T.
Source§impl Client
impl Client
Sourcepub async fn msearch<B: MsearchBundle>(&self, bundle: B) -> Result<B::Output>
pub async fn msearch<B: MsearchBundle>(&self, bundle: B) -> Result<B::Output>
Run several typed searches in one _msearch request, returning one
typed SearchResponse per search, in slot order. The bundle is a
tuple of &Search<T> whose document types may differ:
let (users, orders) = client.msearch((&users_query, &orders_query)).await?;A slot-level failure fails the whole call with Error::Msearch
naming the slot — there are no partial results.
Sourcepub async fn msearch_all<T>(
&self,
searches: &[Search<T>],
) -> Result<Vec<SearchResponse<T>>>where
T: DeserializeOwned,
pub async fn msearch_all<T>(
&self,
searches: &[Search<T>],
) -> Result<Vec<SearchResponse<T>>>where
T: DeserializeOwned,
Run many searches of one document type in a single _msearch
request, returning one SearchResponse per search, in order. The
heterogeneous (mixed-type) form is Client::msearch.