pub struct OsClient { /* private fields */ }Implementations§
Source§impl OsClient
impl OsClient
pub fn new(configuration: Arc<Configuration>) -> Self
pub fn from_environment() -> Result<OsClient, Error>
pub fn indices(&self) -> &IndicesApiClient
pub fn cluster(&self) -> &ClusterApiClient
pub fn ingest(&self) -> &IngestApiClient
pub fn ml(&self) -> &MlApiClient
Sourcepub fn api_version(&self) -> &'static str
pub fn api_version(&self) -> &'static str
Get the version of this API.
This string is pulled directly from the source OpenAPI document and may be in any format the API selects.
Sourcepub async fn bulk_index_document<T: Serialize>(
&self,
index: &str,
id: Option<String>,
body: &T,
) -> Result<(), Error>
pub async fn bulk_index_document<T: Serialize>( &self, index: &str, id: Option<String>, body: &T, ) -> Result<(), Error>
Sends a bulk index request to OpenSearch with the specified index, id and document body.
§Arguments
index- A string slice that holds the name of the index.id- An optional string slice that holds the id of the document.body- A reference to a serializable document body.
§Returns
Returns a Result containing a serde_json::Value representing the response from OpenSearch or an Error if the request fails.
§Example
use opensearch_client::OpenSearchClient;
#[derive(Serialize)]
struct MyDocument {
title: String,
content: String,
}
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let client = OpenSearchClient::new("http://localhost:9200");
let document = MyDocument {
title: "My Title".to_string(),
content: "My Content".to_string(),
};
let response = client
.bulk_index_document("my_index", Some("my_id".to_string()), &document)
.await?;
Ok(())
}Sourcepub async fn bulk_action(
&self,
action: BulkAction,
body: Option<&Value>,
) -> Result<(), Error>
pub async fn bulk_action( &self, action: BulkAction, body: Option<&Value>, ) -> Result<(), Error>
Sends a bulk action to the OpenSearch server.
§Arguments
command- A string slice that holds the command to be executed.action- ABulkActionenum that specifies the action to be taken.body- An optionalserde_json::Valuethat holds the request body.
§Returns
A Result containing a serde_json::Value object representing the
response from the server, or an Error if the request failed.
§Examples
use opensearch_client::{BulkAction, OpenSearchClient};
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let client = OpenSearchClient::new("http://localhost:9200")?;
let action = BulkAction::Index {
index: "my_index".to_string(),
id: Some("1".to_string()),
};
let response = client.bulk_action("index", action, None).await?;
Ok(())
}Sourcepub async fn bulk_create_document<T: Serialize>(
&self,
index: &str,
id: &str,
body: &T,
) -> Result<(), Error>
pub async fn bulk_create_document<T: Serialize>( &self, index: &str, id: &str, body: &T, ) -> Result<(), Error>
Sends a bulk create request to the OpenSearch cluster with the specified index, id and body.
§Arguments
index- A string slice that holds the name of the index.id- A string slice that holds the id of the document.body- A generic typeTthat holds the body of the document to be created.
§Returns
Returns a Result containing a serde_json::Value on success, or an
Error on failure.
Sourcepub async fn bulk_update_document(
&self,
index: &str,
id: &str,
body: &UpdateActionBody,
) -> Result<(), Error>
pub async fn bulk_update_document( &self, index: &str, id: &str, body: &UpdateActionBody, ) -> Result<(), Error>
Asynchronously updates a document in bulk.
§Arguments
index- A string slice that holds the name of the index.id- A string slice that holds the ID of the document to update.body- AnUpdateActionstruct that holds the update action to perform.
§Returns
Returns a Result containing a serde_json::Value on success, or an
Error on failure.
Sourcepub async fn flush_bulk(&self) -> Result<BulkResponse, Error>
pub async fn flush_bulk(&self) -> Result<BulkResponse, Error>
Sends a bulk request to the OpenSearch server and returns a
BulkResponse. If the bulker size is 0, it returns an empty
BulkResponse. If the bulk request contains errors, it logs the errors
and returns the BulkResponse.
§Examples
use opensearch_client::OpenSearchClient;
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let client = OpenSearchClient::new("http://localhost:9200", "user", "password");
let response = client.flush_bulk().await?;
println!("{:?}", response);
Ok(())
}Sourcepub async fn index_document<T: Serialize>(
&self,
index: &str,
body: &T,
id: Option<String>,
) -> Result<IndexResponse, Error>
pub async fn index_document<T: Serialize>( &self, index: &str, body: &T, id: Option<String>, ) -> Result<IndexResponse, Error>
Indexes a document in the specified index with the given body and optional ID.
§Arguments
index- A string slice that holds the name of the index to which the document will be added.body- A reference to a serializable object that represents the document to be added.id- An optional string slice that holds the ID of the document to be added. If not provided, a new ID will be generated.
§Returns
A Result containing an IndexResponse object if the operation was
successful, or an Error if an error occurred.
§Examples
use opensearch_client::Client;
#[derive(Serialize)]
struct MyDocument {
title: String,
content: String,
}
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let client = Client::new("http://localhost:9200")?;
let document = MyDocument {
title: "My Title".to_string(),
content: "My Content".to_string(),
};
let response = client.index_document("my_index", &document, None).await?;
println!("Document ID: {}", response._id);
Ok(())
}Sourcepub async fn create_document<T: Serialize>(
&self,
index: &str,
id: &str,
body: &T,
) -> Result<IndexResponse, Error>
pub async fn create_document<T: Serialize>( &self, index: &str, id: &str, body: &T, ) -> Result<IndexResponse, Error>
Creates a new document in the specified index with the given ID and body.
§Arguments
index- A string slice that holds the name of the index.id- A string slice that holds the ID of the document.body- A generic typeTthat holds the body of the document. The typeTmust implement theSerializetrait from theserdecrate.
§Returns
Returns a Result containing an IndexResponse on success, or an Error
on failure.
§Examples
use opensearch_client::OpenSearchClient;
#[derive(Serialize)]
struct MyDocument {
title: String,
content: String,
}
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let client = OpenSearchClient::new("http://localhost:9200")?;
let document = MyDocument {
title: "My Title".to_string(),
content: "My Content".to_string(),
};
let response = client.create_document("my_index", "1", &document).await?;
Ok(())
}Sourcepub async fn get_typed<T: DeserializeOwned>(
&self,
index: &str,
id: &str,
) -> Result<GetTypedResult<T>, Error>
pub async fn get_typed<T: DeserializeOwned>( &self, index: &str, id: &str, ) -> Result<GetTypedResult<T>, Error>
Asynchronously retrieves a typed document from the specified index and ID.
§Arguments
index- A string slice that holds the name of the index to retrieve the document from.id- A string slice that holds the ID of the document to retrieve.
§Returns
A Result containing the deserialized content of the retrieved document,
or an Error if the operation failed.
§Generic Type Parameters
T- The type of the document to retrieve. Must implement theDeserializeOwnedandstd::default::Defaulttraits.
Sourcepub async fn update_document(
&self,
index: &str,
id: &str,
action: &UpdateActionBody,
) -> Result<IndexResponse, Error>
pub async fn update_document( &self, index: &str, id: &str, action: &UpdateActionBody, ) -> Result<IndexResponse, Error>
Updates a document in the specified index with the given ID using the provided update action.
§Arguments
index- A string slice that holds the name of the index to update the document in.id- A string slice that holds the ID of the document to update.action- A reference to anUpdateActionenum that specifies the update action to perform.
§Returns
Returns a Result containing an IndexResponse struct if the update was
successful, or an Error if an error occurred.
§Example
use opensearch_client::{Client, UpdateAction};
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let client = Client::new("http://localhost:9200")?;
let index = "my_index";
let id = "1";
let action = UpdateAction::new().doc(json!({"foo": "bar"}));
let response = client.update_document(index, id, &action).await?;
Ok(())
}pub fn get_bulker( &self, bulk_size: u32, max_concurrent_connections: u32, ) -> (JoinHandle<()>, Bulker)
pub fn bulker(&self) -> BulkerBuilder
pub async fn search_typed<T: DeserializeOwned>( &self, index: &str, search: Search, ) -> Result<TypedSearchResult<T>, Error>
Sourcepub async fn search_stream<T: DeserializeOwned + Default>(
&self,
index: &str,
query: &Query,
sort: &SortCollection,
size: u64,
) -> Result<impl Stream<Item = TypedHit<T>> + 'static, Error>
pub async fn search_stream<T: DeserializeOwned + Default>( &self, index: &str, query: &Query, sort: &SortCollection, size: u64, ) -> Result<impl Stream<Item = TypedHit<T>> + 'static, Error>
Searches for documents in the specified index and returns a stream of hits.
§Arguments
index- The name of the index to search in.query- The query to execute.sort- The sort criteria to use.size- The maximum number of hits to return.
§Returns
A stream of hits that match the specified search criteria.
§Examples
use opensearch_client::{Client, Query, SortCollection};
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let client = Client::new("http://localhost:9200")?;
let query = Query::match_all();
let sort = SortCollection::new().add_field("_doc", "asc");
let stream = client.search_stream("my_index", &query, &sort, 10).await?;
stream
.for_each(|hit| {
println!("{:?}", hit);
futures::future::ready(())
})
.await;
Ok(())
}Sourcepub fn delete_script<'f1>(&'f1 self) -> OsClientDeleteScriptBuilder<'f1>
pub fn delete_script<'f1>(&'f1 self) -> OsClientDeleteScriptBuilder<'f1>
Deletes a script.
Sourcepub fn termvectors<'f1>(&'f1 self) -> OsClientTermvectorsBuilder<'f1>
pub fn termvectors<'f1>(&'f1 self) -> OsClientTermvectorsBuilder<'f1>
Returns information and statistics about terms in the fields of a particular document.
Sourcepub fn info<'f1>(&'f1 self) -> OsClientInfoBuilder<'f1>
pub fn info<'f1>(&'f1 self) -> OsClientInfoBuilder<'f1>
Returns basic information about the cluster.
Sourcepub fn search_shards<'f1>(&'f1 self) -> OsClientSearchShardsBuilder<'f1>
pub fn search_shards<'f1>(&'f1 self) -> OsClientSearchShardsBuilder<'f1>
Returns information about the indexes and shards that a search request would be executed against.
Sourcepub fn put_script<'f1>(&'f1 self) -> OsClientPutScriptBuilder<'f1>
pub fn put_script<'f1>(&'f1 self) -> OsClientPutScriptBuilder<'f1>
Creates or updates a script.
Sourcepub fn rank_eval<'f1>(&'f1 self) -> OsClientRankEvalBuilder<'f1>
pub fn rank_eval<'f1>(&'f1 self) -> OsClientRankEvalBuilder<'f1>
Allows to evaluate the quality of ranked search results over a set of typical search queries.
Sourcepub fn explain<'f1>(&'f1 self) -> OsClientExplainBuilder<'f1>
pub fn explain<'f1>(&'f1 self) -> OsClientExplainBuilder<'f1>
Returns information about why a specific matches (or doesn’t match) a query.
Sourcepub fn get_script<'f1>(&'f1 self) -> OsClientGetScriptBuilder<'f1>
pub fn get_script<'f1>(&'f1 self) -> OsClientGetScriptBuilder<'f1>
Returns a script.
Sourcepub fn render_search_template<'f1>(
&'f1 self,
) -> OsClientRenderSearchTemplateBuilder<'f1>
pub fn render_search_template<'f1>( &'f1 self, ) -> OsClientRenderSearchTemplateBuilder<'f1>
Allows to use the Mustache language to pre-render a search definition.
Sourcepub fn reindex<'f1>(&'f1 self) -> OsClientReindexBuilder<'f1>
pub fn reindex<'f1>(&'f1 self) -> OsClientReindexBuilder<'f1>
Allows to copy documents from one index to another, optionally filtering the source documents by a query, changing the destination index settings, or fetching the documents from a remote cluster.
Sourcepub fn exists_source<'f1>(&'f1 self) -> OsClientExistsSourceBuilder<'f1>
pub fn exists_source<'f1>(&'f1 self) -> OsClientExistsSourceBuilder<'f1>
Returns information about whether a document source exists in an index.
Sourcepub fn delete_by_query<'f1>(&'f1 self) -> OsClientDeleteByQueryBuilder<'f1>
pub fn delete_by_query<'f1>(&'f1 self) -> OsClientDeleteByQueryBuilder<'f1>
Deletes documents matching the provided query.
Sourcepub fn exists<'f1>(&'f1 self) -> OsClientExistsBuilder<'f1>
pub fn exists<'f1>(&'f1 self) -> OsClientExistsBuilder<'f1>
Returns information about whether a document exists in an index.
Sourcepub fn field_caps<'f1>(&'f1 self) -> OsClientFieldCapsBuilder<'f1>
pub fn field_caps<'f1>(&'f1 self) -> OsClientFieldCapsBuilder<'f1>
Returns the information about the capabilities of fields among multiple indexes.
Sourcepub fn mtermvectors<'f1>(&'f1 self) -> OsClientMtermvectorsBuilder<'f1>
pub fn mtermvectors<'f1>(&'f1 self) -> OsClientMtermvectorsBuilder<'f1>
Returns multiple termvectors in one request.
Sourcepub fn search_with_index<'f1>(&'f1 self) -> OsClientSearchWithIndexBuilder<'f1>
pub fn search_with_index<'f1>(&'f1 self) -> OsClientSearchWithIndexBuilder<'f1>
Returns results matching a query.
Sourcepub fn mget<'f1>(&'f1 self) -> OsClientMgetBuilder<'f1>
pub fn mget<'f1>(&'f1 self) -> OsClientMgetBuilder<'f1>
Allows to get multiple documents in one request.
Sourcepub fn get_script_languages<'f1>(
&'f1 self,
) -> OsClientGetScriptLanguagesBuilder<'f1>
pub fn get_script_languages<'f1>( &'f1 self, ) -> OsClientGetScriptLanguagesBuilder<'f1>
Returns available script types, languages and contexts.
Sourcepub fn clear_scroll<'f1>(&'f1 self) -> OsClientClearScrollBuilder<'f1>
pub fn clear_scroll<'f1>(&'f1 self) -> OsClientClearScrollBuilder<'f1>
Explicitly clears the search context for a scroll.
Sourcepub fn search_template<'f1>(&'f1 self) -> OsClientSearchTemplateBuilder<'f1>
pub fn search_template<'f1>(&'f1 self) -> OsClientSearchTemplateBuilder<'f1>
Allows to use the Mustache language to pre-render a search definition.
Sourcepub fn count<'f1>(&'f1 self) -> OsClientCountBuilder<'f1>
pub fn count<'f1>(&'f1 self) -> OsClientCountBuilder<'f1>
Returns number of documents matching a query.
Sourcepub fn search_shards_with_index<'f1>(
&'f1 self,
) -> OsClientSearchShardsWithIndexBuilder<'f1>
pub fn search_shards_with_index<'f1>( &'f1 self, ) -> OsClientSearchShardsWithIndexBuilder<'f1>
Returns information about the indexes and shards that a search request would be executed against.
Sourcepub fn reindex_rethrottle<'f1>(
&'f1 self,
) -> OsClientReindexRethrottleBuilder<'f1>
pub fn reindex_rethrottle<'f1>( &'f1 self, ) -> OsClientReindexRethrottleBuilder<'f1>
Changes the number of requests per second for a particular reindex operation.
Sourcepub fn create<'f1>(&'f1 self) -> OsClientCreateBuilder<'f1>
pub fn create<'f1>(&'f1 self) -> OsClientCreateBuilder<'f1>
Creates a new document in the index.
Returns a 409 response when a document with a same ID already exists in the index.
Sourcepub fn get_source<'f1>(&'f1 self) -> OsClientGetSourceBuilder<'f1>
pub fn get_source<'f1>(&'f1 self) -> OsClientGetSourceBuilder<'f1>
Returns the source of a document.
Sourcepub fn bulk<'f1>(&'f1 self) -> OsClientBulkBuilder<'f1>
pub fn bulk<'f1>(&'f1 self) -> OsClientBulkBuilder<'f1>
Allows to perform multiple index/update/delete operations in a single request.
Sourcepub fn scroll<'f1>(&'f1 self) -> OsClientScrollBuilder<'f1>
pub fn scroll<'f1>(&'f1 self) -> OsClientScrollBuilder<'f1>
Allows to retrieve a large numbers of results from a single search request.
Sourcepub fn msearch<'f1>(&'f1 self) -> OsClientMsearchBuilder<'f1>
pub fn msearch<'f1>(&'f1 self) -> OsClientMsearchBuilder<'f1>
Allows to execute several search operations in one request.
Sourcepub fn scripts_painless_execute<'f1>(
&'f1 self,
) -> OsClientScriptsPainlessExecuteBuilder<'f1>
pub fn scripts_painless_execute<'f1>( &'f1 self, ) -> OsClientScriptsPainlessExecuteBuilder<'f1>
Allows an arbitrary script to be executed and a result to be returned.
Sourcepub fn update_by_query<'f1>(&'f1 self) -> OsClientUpdateByQueryBuilder<'f1>
pub fn update_by_query<'f1>(&'f1 self) -> OsClientUpdateByQueryBuilder<'f1>
Performs an update on every document in the index without changing the source, for example to pick up a mapping change.
Sourcepub fn update_by_query_raw<'f1>(
&'f1 self,
) -> OsClientUpdateByQueryRawBuilder<'f1>
pub fn update_by_query_raw<'f1>( &'f1 self, ) -> OsClientUpdateByQueryRawBuilder<'f1>
Performs an update on every document in the index without changing the source, for example to pick up a mapping change.
Sourcepub fn update_by_query_rethrottle<'f1>(
&'f1 self,
) -> OsClientUpdateByQueryRethrottleBuilder<'f1>
pub fn update_by_query_rethrottle<'f1>( &'f1 self, ) -> OsClientUpdateByQueryRethrottleBuilder<'f1>
Changes the number of requests per second for a particular Update By Query operation.
Sourcepub fn get_script_context<'f1>(
&'f1 self,
) -> OsClientGetScriptContextBuilder<'f1>
pub fn get_script_context<'f1>( &'f1 self, ) -> OsClientGetScriptContextBuilder<'f1>
Returns all script contexts.
Sourcepub fn delete_by_query_rethrottle<'f1>(
&'f1 self,
) -> OsClientDeleteByQueryRethrottleBuilder<'f1>
pub fn delete_by_query_rethrottle<'f1>( &'f1 self, ) -> OsClientDeleteByQueryRethrottleBuilder<'f1>
Changes the number of requests per second for a particular Delete By Query operation.
Sourcepub fn search_template_with_index<'f1>(
&'f1 self,
) -> OsClientSearchTemplateWithIndexBuilder<'f1>
pub fn search_template_with_index<'f1>( &'f1 self, ) -> OsClientSearchTemplateWithIndexBuilder<'f1>
Allows to use the Mustache language to pre-render a search definition.
Sourcepub fn msearch_template<'f1>(&'f1 self) -> OsClientMsearchTemplateBuilder<'f1>
pub fn msearch_template<'f1>(&'f1 self) -> OsClientMsearchTemplateBuilder<'f1>
Allows to execute several search template operations in one request.
Sourcepub fn ping<'f1>(&'f1 self) -> OsClientPingBuilder<'f1>
pub fn ping<'f1>(&'f1 self) -> OsClientPingBuilder<'f1>
Returns whether the cluster is running.
Sourcepub fn index<'f1>(&'f1 self) -> OsClientIndexBuilder<'f1>
pub fn index<'f1>(&'f1 self) -> OsClientIndexBuilder<'f1>
Creates or updates a document in an index.
Sourcepub fn update<'f1>(&'f1 self) -> OsClientUpdateBuilder<'f1>
pub fn update<'f1>(&'f1 self) -> OsClientUpdateBuilder<'f1>
Updates a document with a script or partial document.
Sourcepub fn update_raw<'f1>(&'f1 self) -> OsClientUpdateRawBuilder<'f1>
pub fn update_raw<'f1>(&'f1 self) -> OsClientUpdateRawBuilder<'f1>
Updates a document with a script or partial document.