qdrant_client/qdrant_client/
index.rs

1use crate::qdrant::{
2    CreateFieldIndexCollection, DeleteFieldIndexCollection, PointsOperationResponse,
3};
4use crate::qdrant_client::{Qdrant, QdrantResult};
5
6/// # Index operations
7///
8/// Manage field and payload indices in collections.
9///
10/// Documentation: <https://qdrant.tech/documentation/concepts/indexing/>
11impl Qdrant {
12    /// Create payload index in a collection.
13    ///
14    /// ```no_run
15    ///# use std::collections::HashMap;
16    ///# use qdrant_client::{Qdrant, QdrantError};
17    /// use qdrant_client::qdrant::{CreateFieldIndexCollectionBuilder, FieldType};
18    ///
19    ///# async fn create_field_index(client: &Qdrant)
20    ///# -> Result<(), QdrantError> {
21    /// client
22    ///     .create_field_index(
23    ///         CreateFieldIndexCollectionBuilder::new(
24    ///             "my_collection",
25    ///             "city",
26    ///             FieldType::Keyword,
27    ///         ),
28    ///     )
29    ///     .await?;
30    ///# Ok(())
31    ///# }
32    /// ```
33    ///
34    /// Documentation: <https://qdrant.tech/documentation/concepts/indexing/#payload-index>
35    pub async fn create_field_index(
36        &self,
37        request: impl Into<CreateFieldIndexCollection>,
38    ) -> QdrantResult<PointsOperationResponse> {
39        let request = &request.into();
40
41        self.with_points_client(|mut client| async move {
42            let result = client.create_field_index(request.clone()).await?;
43            Ok(result.into_inner())
44        })
45        .await
46    }
47
48    /// Delete payload index from a collection.
49    ///
50    /// ```no_run
51    ///# use std::collections::HashMap;
52    ///# use qdrant_client::{Qdrant, QdrantError};
53    /// use qdrant_client::qdrant::DeleteFieldIndexCollectionBuilder;
54    ///
55    ///# async fn create_field_index(client: &Qdrant)
56    ///# -> Result<(), QdrantError> {
57    /// client
58    ///     .delete_field_index(DeleteFieldIndexCollectionBuilder::new(
59    ///         "my_collection",
60    ///         "city",
61    ///     ))
62    ///     .await?;
63    ///# Ok(())
64    ///# }
65    /// ```
66    ///
67    /// Documentation: <https://qdrant.tech/documentation/concepts/indexing/#payload-index>
68    pub async fn delete_field_index(
69        &self,
70        request: impl Into<DeleteFieldIndexCollection>,
71    ) -> QdrantResult<PointsOperationResponse> {
72        let request = &request.into();
73
74        self.with_points_client(|mut client| async move {
75            let result = client.delete_field_index(request.clone()).await?;
76            Ok(result.into_inner())
77        })
78        .await
79    }
80}