Skip to content

create_index

create_index(
    id: CollectionId,
    index_name: IndexName,
    *,
    config_overrides: Optional[OpenSearchServerlessClientConfig] = None,
    index_schema: Optional[IndexSchema] = None,
) -> CreateIndexResponse

Creates an index within an OpenSearch Serverless collection. Unlike other OpenSearch indexes, indexes created by this API are automatically configured to conduct automatic semantic enrichment ingestion and search. For more information, see About automatic semantic enrichment in the OpenSearch User Guide.

Parameters:

  • id (CollectionId) –

    The unique identifier of the collection in which to create the index.

  • index_name (IndexName) –

    The name of the index to create. Index names must be lowercase and can't begin with underscores (_) or hyphens (-).

  • index_schema (Optional[IndexSchema], default: None ) –

    The JSON schema definition for the index, including field mappings and settings.

Raises:

  • ConflictException –

    When creating a resource, thrown when a resource with the same name already exists or is being created. When deleting a resource, thrown when the resource is not in the ACTIVE, FAILED, or UPDATE_FAILED state.

  • InternalServerException –

    Thrown when an error internal to the service occurs while processing a request.

  • ResourceNotFoundException –

    Thrown when accessing or deleting a resource that does not exist.

  • ValidationException –

    Thrown when the HTTP request contains invalid input or is missing required input.

  • UnknownServiceError –

    The service returned an error code this client does not model.

Source code in docs_src/capo_opensearchserverless/_services/open_search_serverless.py
def create_index(
    self,
    id: "capo_opensearchserverless.types.collection_id.CollectionId",
    index_name: "capo_opensearchserverless.types.index_name.IndexName",
    *,
    config_overrides: Optional[OpenSearchServerlessClientConfig] = None,
    index_schema: Optional[
        "capo_opensearchserverless.types.index_schema.IndexSchema"
    ] = None,
) -> "capo_opensearchserverless.types.create_index_response.CreateIndexResponse":
    """<p>Creates an index within an OpenSearch Serverless collection. Unlike other OpenSearch indexes, indexes created by this API are automatically configured to conduct automatic semantic enrichment ingestion and search. For more information, see <a href="https://docs.aws.amazon.com/opensearch-service/latest/developerguide/serverless-manage.html#serverless-semantic-enrichment">About automatic semantic enrichment</a> in the <i>OpenSearch User Guide</i>.</p>

    Args:
        id: <p>The unique identifier of the collection in which to create the index.</p>
        index_name: <p>The name of the index to create. Index names must be lowercase and can't begin with underscores (_) or hyphens (-).</p>
        index_schema: <p>The JSON schema definition for the index, including field mappings and settings.</p>

    Raises:
        capo_opensearchserverless.errors.conflict_exception.ConflictException: <p>When creating a resource, thrown when a resource with the same name already exists or is being created. When deleting a resource, thrown when the resource is not in the ACTIVE, FAILED, or UPDATE_FAILED state.</p>
        capo_opensearchserverless.errors.internal_server_exception.InternalServerException: <p>Thrown when an error internal to the service occurs while processing a request.</p>
        capo_opensearchserverless.errors.resource_not_found_exception.ResourceNotFoundException: <p>Thrown when accessing or deleting a resource that does not exist.</p>
        capo_opensearchserverless.errors.validation_exception.ValidationException: <p>Thrown when the HTTP request contains invalid input or is missing required input.</p>
        capo_opensearchserverless.errors.UnknownServiceError: The service returned an error code this client does not model.
    """

    def _handler(
        req: "OperationRequest[capo_opensearchserverless.types.create_index_request.CreateIndexRequest]",
    ) -> OperationResponse[
        "capo_opensearchserverless.types.create_index_response.CreateIndexResponse"
    ]:
        import capo_opensearchserverless._operations.open_search_serverless.create_index

        output, http_response = (
            capo_opensearchserverless._operations.open_search_serverless.create_index.create_index(
                req.options, req.input
            )
        )
        return OperationResponse(output=output, response=http_response)

    interceptors_, options_ = self.operation_options(
        config_overrides, OperationLogging("CreateIndex")
    )
    input_: capo_opensearchserverless.types.create_index_request.CreateIndexRequest = {
        "id": id,
        "index_name": index_name,
    }
    if index_schema is not None:
        input_["index_schema"] = index_schema

    response = execute_pipeline(
        OperationRequest(input=input_, options=options_),
        handler=_handler,
        interceptors=list(interceptors_),
    )
    response.response.close()
    return response.output