你当前正在访问 Microsoft Azure Global Edition 技术文档网站。 如果需要访问由世纪互联运营的 Microsoft Azure 中国技术文档网站,请访问 https://docs.azure.cn。

快速入门:使用 Bicep 部署 Azure AI 搜索

注意

Azure AI 搜索可通过Azure门户、REST API 和Azure SDK获取。 它也是 Foundry IQ 的基础;Foundry IQ 是一个托管式知识层,可将企业内容转化为供 Microsoft Foundry 门户中的智能体使用的、可复用且具备权限感知能力的知识库。

在本快速入门中,使用Bicep文件在Azure门户中部署Azure AI 搜索服务。

Bicep 是一种特定于域的语言 (DSL),使用声明性语法来部署 Azure 资源。 它提供简明的语法、可靠的类型安全性以及对代码重用的支持。 Bicep 会针对你的 Azure 基础结构即代码解决方案提供最佳创作体验。

部署仅使用模板中包含的属性。 如果需要更多自定义,例如 设置网络安全,则可以将服务更新为部署后任务。 若要以最少的步骤自定义现有服务,请使用 Azure CLI 或 Azure PowerShell。 如果要评估预览功能,请使用管理 REST API。

提示

有关使用预配置索引器将Azure AI 搜索部署到 Cosmos DB for NoSQL的替代Bicep模板,请参阅Bicep部署Azure AI 搜索。 没有Bicep模板支持Azure AI 搜索数据平面操作,例如创建索引,但可以添加调用 REST API 的模块。 此示例包含一个模块,用于创建索引、数据源连接器和以 5 分钟的间隔从 Cosmos DB 刷新的索引器。

先决条件

如果没有 Azure 订阅,请在开始之前创建一个免费帐户。

查阅 Bicep 文件

本快速入门使用 Azure 快速入门模板 中的 Bicep 文件。

@description('Service name must only contain lowercase letters, digits or dashes, cannot use dash as the first two or last one characters, cannot contain consecutive dashes, and is limited between 2 and 60 characters in length.')
@minLength(2)
@maxLength(60)
param name string

@allowed([
  'free'
  'basic'
  'standard'
  'standard2'
  'standard3'
  'storage_optimized_l1'
  'storage_optimized_l2'
])
@description('The pricing tier of the search service you want to create (for example, basic or standard).')
param sku string = 'standard'

@description('Replicas distribute search workloads across the service. You need at least two replicas to support high availability of query workloads (not applicable to the free tier).')
@minValue(1)
@maxValue(12)
param replicaCount int = 1

@description('Partitions allow for scaling of document count as well as faster indexing by sharding your index over multiple search units.')
@allowed([
  1
  2
  3
  4
  6
  12
])
param partitionCount int = 1

@description('Applicable only for SKUs set to standard3. You can set this property to enable a single, high density partition that allows up to 1000 indexes, which is much higher than the maximum indexes allowed for any other SKU.')
@allowed([
  'default'
  'highDensity'
])
param hostingMode string = 'default'

@description('Location for all resources.')
param location string = resourceGroup().location

resource search 'Microsoft.Search/searchServices@2020-08-01' = {
  name: name
  location: location
  sku: {
    name: sku
  }
  properties: {
    replicaCount: replicaCount
    partitionCount: partitionCount
    hostingMode: hostingMode
  }
}

Bicep文件定义以下Azure资源:

部署 Bicep 文件

  1. 将 Bicep 文件在本地计算机上另存为 main.bicep。

  2. 使用 Azure CLI 或 Azure PowerShell 部署 Bicep 文件。

    az group create --name exampleRG --location eastus
    az deployment group create --resource-group exampleRG --template-file main.bicep --parameters serviceName=<service-name>
    

    注意

    在 <service-name> 处输入搜索服务的名称以进行替换。 服务名称必须仅包含小写字母、数字或短划线。 不能使用短划线作为前两个字符或最后一个字符。 名称的最小长度为 2 个字符,最大长度为 60 个字符。

    部署完成后,可看到一条指示部署成功的消息。

查看已部署的资源

使用 Azure 门户、Azure CLI 或 Azure PowerShell 列出资源组中已部署的资源。

az resource list --resource-group exampleRG

清理资源

Azure AI 搜索是一项计费资源。 如果不再需要它,请将其从订阅中删除,以避免产生费用。 可以使用 Azure 门户、Azure CLI 或 Azure PowerShell 删除资源组及其资源。

az group delete --name exampleRG

在本快速入门中,你使用 Bicep 文件创建了 Azure AI 搜索服务,然后验证了部署。 若要详细了解 Azure AI 搜索和 Azure 资源管理器,请参阅以下文章: