本文属于机器翻译版本。若本译文内容与英语原文存在差异,则一律以英文原文为准。
创建集合(CLI)
使用本节中的过程使用创建 OpenSearch 无服务器集合。 AWS CLI
开始前的准备工作
在使用创建集合之前 AWS CLI,请按照以下步骤为该集合创建所需的策略。
注意
在以下每个过程中,当您为集合指定名称时,该名称必须满足以下条件:
-
是您的账户所独有的 AWS 区域
-
只包含小写字母 a-z、数字 0–9 和连字符(-)
-
包含 3 到 32 个字符
为集合创建必需的策略
-
打开 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/*
。 -
运行以下命令,使用网络策略为集合配置网络设置。您可以在创建集合后创建网络策略,但我们建议您事先创建网络策略。
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}]"
创建集合
以下过程使用 CreateCollectionAPI 操作创建类型为SEARCH
或的集合TIMESERIES
。如果您在该请求中未指定集合类型,则其默认为 TIMESERIES
。有关这些类型的更多信息,请参阅选择集合类型。要创建向量搜索集合,请参阅 使用向量搜索集合。
如果您的馆藏使用加密 AWS 拥有的密钥,则kmsKeyArn
为,auto
而不是 ARN。
重要
在创建集合后,除非该集合与某一数据访问策略相匹配,否则您将无法访问它。有关更多信息,请参阅 Amazon OpenSearch 无服务器的数据访问控制。
创建集合
-
验证您是否创建了中描述的必需策略开始前的准备工作。
-
运行以下命令。为此,
type
请指定SEARCH
或TIMESERIES
。aws opensearchserverless create-collection --name "
collection name
" --typecollection type
--description "description
"
使用自动语义丰富索引创建集合
使用以下步骤创建新的 OpenSearch Serverless 集合,其索引已配置为自动语义丰富。该过程使用 OpenSearch 无服务器 CreateIndexAPI 操作。
使用配置为自动语义丰富功能的索引创建新集合
运行以下命令来创建集合和索引。
aws opensearchserverless create-index \ --region
Region ID
\ --idcollection name
--index-nameindex 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" } } } } }'