qdrant_client/qdrant_client/sharding_keys.rs
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81
use crate::qdrant::{
CreateShardKeyRequest, CreateShardKeyResponse, DeleteShardKeyRequest, DeleteShardKeyResponse,
};
use crate::qdrant_client::{Qdrant, QdrantResult};
/// # Sharding key operations
///
/// Create or delete shard keys for collections.
///
/// Documentation: <https://qdrant.tech/documentation/guides/distributed_deployment/#user-defined-sharding>
impl Qdrant {
/// Create new shard key in a collection.
///
/// ```no_run
///# use qdrant_client::{Qdrant, QdrantError};
/// use qdrant_client::qdrant::shard_key::Key;
/// use qdrant_client::qdrant::{CreateShardKeyBuilder, CreateShardKeyRequestBuilder};
///
///# async fn create_shard_key(client: &Qdrant)
///# -> Result<(), QdrantError> {
/// client
/// .create_shard_key(
/// CreateShardKeyRequestBuilder::new("my_collection").request(
/// CreateShardKeyBuilder::default()
/// .shard_key(Key::Keyword("my_key".to_string())),
/// ),
/// )
/// .await?;
///# Ok(())
///# }
/// ```
///
/// Documentation: <https://qdrant.tech/documentation/guides/distributed_deployment/#user-defined-sharding>
pub async fn create_shard_key(
&self,
request: impl Into<CreateShardKeyRequest>,
) -> QdrantResult<CreateShardKeyResponse> {
let request = &request.into();
self.with_collections_client(|mut collection_api| async move {
let result = collection_api.create_shard_key(request.clone()).await?;
Ok(result.into_inner())
})
.await
}
/// Delete existing shard key from a collection.
///
/// Deleting a shard key destroys all shards and data placed in it.
///
/// ```no_run
///# use qdrant_client::{Qdrant, QdrantError};
/// use qdrant_client::qdrant::shard_key::Key;
/// use qdrant_client::qdrant::DeleteShardKeyRequestBuilder;
///
///# async fn delete_shard_key(client: &Qdrant)
///# -> Result<(), QdrantError> {
/// client
/// .delete_shard_key(
/// DeleteShardKeyRequestBuilder::new("my_collection")
/// .key(Key::Keyword("my_key".to_string())),
/// )
/// .await?;
///# Ok(())
///# }
/// ```
///
/// Documentation: <https://qdrant.tech/documentation/guides/distributed_deployment/#user-defined-sharding>
pub async fn delete_shard_key(
&self,
request: impl Into<DeleteShardKeyRequest>,
) -> QdrantResult<DeleteShardKeyResponse> {
let request = &request.into();
self.with_collections_client(|mut collection_api| async move {
let result = collection_api.delete_shard_key(request.clone()).await?;
Ok(result.into_inner())
})
.await
}
}