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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
use crate::qdrant::{
CreateShardKeyRequest, CreateShardKeyResponse, DeleteShardKeyRequest, DeleteShardKeyResponse,
ListShardKeysRequest, ListShardKeysResponse,
};
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
}
/// List all shard keys in a collection.
///
/// ```no_run
///# use qdrant_client::{Qdrant, QdrantError};
///# async fn list_shard_keys(client: &Qdrant)
///# -> Result<(), QdrantError> {
/// let response = client.list_shard_keys("my_collection").await?;
///# Ok(())
///# }
/// ```
///
/// Documentation: <https://qdrant.tech/documentation/guides/distributed_deployment/#user-defined-sharding>
pub async fn list_shard_keys(
&self,
request: impl Into<ListShardKeysRequest>,
) -> QdrantResult<ListShardKeysResponse> {
let request = &request.into();
self.with_collections_client(|mut collection_api| async move {
let result = collection_api.list_shard_keys(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
}
}