Performs management operations on query indexes. For managing query indexes at the collection level, :class:`.CollectionQueryIndexManager` should be used.
| 39 | |
| 40 | |
| 41 | class QueryIndexManager: |
| 42 | """ |
| 43 | Performs management operations on query indexes. |
| 44 | |
| 45 | For managing query indexes at the collection level, :class:`.CollectionQueryIndexManager` should be used. |
| 46 | """ |
| 47 | |
| 48 | def __init__(self, client_adapter: ClientAdapter, observability_instruments: ObservabilityInstruments) -> None: |
| 49 | self._impl = QueryIndexMgmtImpl(client_adapter, observability_instruments) |
| 50 | self._collection_ctx = None |
| 51 | |
| 52 | def create_index(self, |
| 53 | bucket_name, # type: str |
| 54 | index_name, # type: str |
| 55 | keys, # type: Iterable[str] |
| 56 | *options, # type: CreateQueryIndexOptions |
| 57 | **kwargs # type: Dict[str, Any] |
| 58 | ) -> None: |
| 59 | """Creates a new query index. |
| 60 | |
| 61 | Args: |
| 62 | bucket_name (str): The name of the bucket this index is for. |
| 63 | index_name (str): The name of the index. |
| 64 | keys (Iterable[str]): The keys which this index should cover. |
| 65 | options (:class:`~couchbase.management.options.CreateQueryIndexOptions`): Optional parameters for this |
| 66 | operation. |
| 67 | **kwargs (Dict[str, Any]): keyword arguments that can be used as optional parameters |
| 68 | for this operation. |
| 69 | |
| 70 | Raises: |
| 71 | :class:`~couchbase.exceptions.InvalidArgumentException`: If the bucket_name, index_name or keys |
| 72 | are invalid types. |
| 73 | :class:`~couchbase.exceptions.QueryIndexAlreadyExistsException`: If the index already exists. |
| 74 | """ |
| 75 | op_type = QueryIndexMgmtOperationType.QueryIndexCreate |
| 76 | with ObservableRequestHandler(op_type, self._impl.observability_instruments) as obs_handler: |
| 77 | req = self._impl.request_builder.build_create_index_request(bucket_name, |
| 78 | index_name, |
| 79 | keys, |
| 80 | obs_handler, |
| 81 | self._collection_ctx, |
| 82 | *options, |
| 83 | **kwargs) |
| 84 | self._impl.create_index(req, obs_handler) |
| 85 | |
| 86 | def create_primary_index(self, |
| 87 | bucket_name, # type: str |
| 88 | *options, # type: CreatePrimaryQueryIndexOptions |
| 89 | **kwargs # type: Dict[str, Any] |
| 90 | ) -> None: |
| 91 | """Creates a new primary query index. |
| 92 | |
| 93 | Args: |
| 94 | bucket_name (str): The name of the bucket this index is for. |
| 95 | options (:class:`~couchbase.management.options.CreatePrimaryQueryIndexOptions`): Optional parameters for |
| 96 | this operation. |
| 97 | **kwargs (Dict[str, Any]): keyword arguments that can be used as optional parameters |
| 98 | for this operation. |