Share via


快速入門:使用 Bicep 部署 Azure AI 搜尋

本文將逐步引導您完成使用 Bicep 檔案在 Azure 入口網站 中部署 Azure AI 搜尋資源的程式。

Bicep 是使用宣告式語法來部署 Azure 資源的特定領域語言 (DSL)。 其提供簡潔的語法、可靠的類型安全,並支援程式碼重複使用。 Bicep 能夠為您在 Azure 中的基礎結構即程式碼解決方案,提供最佳的製作體驗。

部署中只會使用範本中包含的屬性。 如果需要更多自定義,例如 設定網路安全性,您可以將服務更新為部署後工作。 若要使用最少的步驟自定義現有的服務,請使用 Azure CLIAzure PowerShell。 如果您正在評估預覽功能,請使用 管理 REST API

提示

如需使用預先設定索引器將 Azure AI 搜尋部署至 Cosmos DB for NoSQL 的替代 Bicep 範本,請參閱 Azure AI 搜尋的 Bicep 部署。 Azure AI 搜尋服務數據平面作業沒有 Bicep 範本支援,例如建立索引,但您可以新增呼叫 REST API 的模組。 此範例包含一個模組,其會建立索引、數據源連接器,以及以 5 分鐘間隔從 Cosmos DB 重新整理的索引器。

必要條件

如果您沒有 Azure 訂用帳戶,請在開始前建立免費帳戶

檢閱 Bicep 檔案

此快速入門中使用的 Bicep 檔案是來自 Azure 快速入門範本

@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 Resource Manager,請繼續閱讀文章。