Allows to manage scope-level search indexes in a Couchbase cluster.
| 411 | |
| 412 | |
| 413 | class ScopeSearchIndexManager: |
| 414 | """ |
| 415 | Allows to manage scope-level search indexes in a Couchbase cluster. |
| 416 | """ |
| 417 | |
| 418 | def __init__(self, client_adapter: ClientAdapter, bucket_name: str, scope_name: str, observability_instruments: ObservabilityInstruments) -> None: # noqa: E501 |
| 419 | self._impl = SearchIndexMgmtImpl(client_adapter, observability_instruments) |
| 420 | self._scope_context = bucket_name, scope_name |
| 421 | |
| 422 | def upsert_index(self, |
| 423 | index, # type: SearchIndex |
| 424 | *options, # type: UpsertSearchIndexOptions |
| 425 | **kwargs # type: Any |
| 426 | ) -> None: |
| 427 | """Creates or updates an index. |
| 428 | |
| 429 | Args: |
| 430 | index (:class:`.SearchIndex`): The index definition. |
| 431 | options (:class:`~couchbase.management.options.UpsertSearchIndexOptions`): Optional parameters for this |
| 432 | operation. |
| 433 | **kwargs (Dict[str, Any]): keyword arguments that can be used as optional parameters for this operation. |
| 434 | |
| 435 | Raises: |
| 436 | :class:`~couchbase.exceptions.InvalidArgumentException`: If the index definition is invalid. |
| 437 | """ |
| 438 | op_type = SearchIndexMgmtOperationType.SearchIndexUpsert |
| 439 | with ObservableRequestHandler(op_type, self._impl.observability_instruments) as obs_handler: |
| 440 | req = self._impl.request_builder.build_upsert_index_request(index, |
| 441 | self._scope_context, |
| 442 | obs_handler, |
| 443 | *options, |
| 444 | **kwargs) |
| 445 | self._impl.upsert_index(req, obs_handler) |
| 446 | |
| 447 | def drop_index(self, |
| 448 | index_name, # type: str |
| 449 | *options, # type: DropSearchIndexOptions |
| 450 | **kwargs # type: Any |
| 451 | ) -> None: |
| 452 | """Drops an index. |
| 453 | |
| 454 | Args: |
| 455 | index_name (str): The name of the index. |
| 456 | options (:class:`~couchbase.management.options.DropSearchIndexOptions`): Optional parameters for this |
| 457 | operation. |
| 458 | **kwargs (Dict[str, Any]): keyword arguments that can be used as optional parameters for this operation. |
| 459 | |
| 460 | Raises: |
| 461 | :class:`~couchbase.exceptions.SearchIndexNotFoundException`: If the index does not exist. |
| 462 | """ |
| 463 | op_type = SearchIndexMgmtOperationType.SearchIndexDrop |
| 464 | with ObservableRequestHandler(op_type, self._impl.observability_instruments) as obs_handler: |
| 465 | req = self._impl.request_builder.build_drop_index_request(index_name, |
| 466 | self._scope_context, |
| 467 | obs_handler, |
| 468 | *options, |
| 469 | **kwargs) |
| 470 | self._impl.drop_index(req, obs_handler) |