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