建立集合 (CLI) - Amazon OpenSearch Service

本文為英文版的機器翻譯版本,如內容有任何歧義或不一致之處,概以英文版為準。

建立集合 (CLI)

使用本節中的程序,使用 建立 OpenSearch Serverless 集合 AWS CLI。

開始之前

使用 建立集合之前 AWS CLI,請使用下列程序來建立集合所需的政策。

注意

在下列每個程序中,當您指定集合的名稱時,名稱必須符合下列條件:

  • 專屬於您的帳戶和 AWS 區域

  • 只能包含小寫字母 a-z、數字 0-9 和連字號 (-)

  • 包含 3 到 32 個之間字元數

建立集合所需的政策
  1. 開啟 AWS CLI 並執行下列命令,以建立資源模式符合集合預期名稱的加密政策

    aws opensearchserverless create-security-policy \ --name policy name \ --type encryption --policy "{\"Rules\":[{\"ResourceType\":\"collection\",\"Resource\":[\"collection\/collection name\"]}],\"AWSOwnedKey\":true}"

    例如,如果您計劃將集合命名為 logs-application,則可以建立如下所示的加密政策:

    aws opensearchserverless create-security-policy \ --name logs-policy \ --type encryption --policy "{\"Rules\":[{\"ResourceType\":\"collection\",\"Resource\":[\"collection\/logs-application\"]}],\"AWSOwnedKey\":true}"

    如果您計劃將政策用於其他集合,則可以使規則的範圍更廣泛,例如 collection/logs*collection/*

  2. 執行下列命令,使用網路政策來設定集合的網路設定。您可以在建立集合之後建立網路政策,但建議您事先執行此操作。

    aws opensearchserverless create-security-policy \ --name policy name \ --type network --policy "[{\"Description\":\"description\",\"Rules\":[{\"ResourceType\":\"dashboard\",\"Resource\":[\"collection\/collection name\"]},{\"ResourceType\":\"collection\",\"Resource\":[\"collection\/collection name\"]}],\"AllowFromPublic\":true}]"

    使用先前的 logs-application 範例,您可建立下列網路政策:

    aws opensearchserverless create-security-policy \ --name logs-policy \ --type network --policy "[{\"Description\":\"Public access for logs collection\",\"Rules\":[{\"ResourceType\":\"dashboard\",\"Resource\":[\"collection\/logs-application\"]},{\"ResourceType\":\"collection\",\"Resource\":[\"collection\/logs-application\"]}],\"AllowFromPublic\":true}]"

建立集合

下列程序使用 CreateCollection API 動作來建立類型 SEARCH或 的集合TIMESERIES。如果您未在請求中指定集合類型,即會預設為 TIMESERIES。如需這些類型的詳細資訊,請參閱 選擇集合類型。若要建立向量搜尋集合,請參閱 使用向量搜尋集合

如果您的集合使用 加密 AWS 擁有的金鑰,則 kmsKeyArnauto不是 ARN。

重要

建立集合後,除非該集合符合資料存取政策,否則您將無法存取它。如需詳細資訊,請參閱Amazon OpenSearch Serverless 的資料存取控制

建立集合
  1. 確認您已建立 中所述的必要政策開始之前

  2. 執行下列命令。對於 ,type請指定 SEARCHTIMESERIES

    aws opensearchserverless create-collection --name "collection name" --type collection type --description "description"

使用自動語意擴充索引建立集合

使用下列程序,使用為自動語意擴充設定的索引建立新的 OpenSearch Serverless 集合。程序使用 OpenSearch Serverless CreateIndex API 動作。

使用為自動語意擴充設定的索引建立新的集合

執行下列命令來建立集合和索引。

aws opensearchserverless create-index \ --region Region ID \ --id collection name --index-name index name \ --index-schema \ 'mapping in json'

範例如下。

aws opensearchserverless create-index \ --region us-east-1 \ --id conversation_history --index-name conversation_history_index \ --index-schema \ '{ "mappings": { "properties": { "age": { "type": "integer" }, "name": { "type": "keyword" }, "user_description": { "type": "text" }, "conversation_history": { "type": "text", "semantic_enrichment": { "status": "ENABLED", // Specifies the sparse tokenizer for processing multi-lingual text "language_option": "MULTI-LINGUAL", // If embedding_field is provided, the semantic embedding field will be set to the given name rather than original field name + "_embedding" "embedding_field": "conversation_history_user_defined" } }, "book_title": { "type": "text", "semantic_enrichment": { // No embedding_field is provided, so the semantic embedding field is set to "book_title_embedding" "status": "ENABLED", "language_option": "ENGLISH" } }, "abstract": { "type": "text", "semantic_enrichment": { // If no language_option is provided, it will be set to English. // No embedding_field is provided, so the semantic embedding field is set to "abstract_embedding" "status": "ENABLED" } } } } }'