【问题标题】:Adding index creation/configuration in a Azure search ARM Template在 Azure 搜索 ARM 模板中添加索引创建/配置
【发布时间】:2016-08-11 12:49:11
【问题描述】:

可以通过 ARM 模板创建 Azure 搜索服务(例如:https://raw.githubusercontent.com/azure/azure-quickstart-templates/master/101-azure-search-create/azuredeploy.json)。

我想知道有没有办法在 ARM 模板中定义特定索引(字段、数据源、索引器等)?

我知道您可以使用 REST 服务来创建和修改索引,但我不希望在创建资源组和 Azure 搜索服务后使用单独的脚本/应用程序来处理它。

【问题讨论】:

    标签: azure azure-cognitive-search arm-template


    【解决方案1】:

    +1 对唐的评论。您将需要使用REST API.NET SDK 创建索引。如果您碰巧使用 PowerShell 创建服务,您可能会发现以下代码很有帮助,它使用 Invoke-RestMethod 和一组包含索引架构和一些文档的 .JSON 文件调用 REST API。

    #------------------------#
    # Setting up search index#
    #------------------------#
    $headers = New-Object "System.Collections.Generic.Dictionary[[String],[String]]"
    $headers.Add("Content-Type", 'application/json')
    $headers.Add("api-key", $searchApiKey)
    
    Write-Host 
    Write-Host "Creating Index..."
    $schemaFile = "$(Split-Path $MyInvocation.MyCommand.Path)\zipcodes.schema"
    $response = Invoke-RestMethod -TimeoutSec 10000 $searchServiceUrl"/indexes/zipcodes2?api-version=2015-02-28-Preview" -Method Put -Headers $headers -Body "$(get-content $schemaFile)"
    Write-Host $response
    
    $jsonFile = "$(Split-Path $MyInvocation.MyCommand.Path)\zipcodes1.json"
    Write-Host 
    Write-Host "Adding Documents from $jsonFile..."
    $response = Invoke-RestMethod -TimeoutSec 10000 $searchServiceUrl"/indexes/zipcodes2/docs/index?api-version=2015-02-28-Preview" -Method Post -Headers $headers -Body "$(get-content $jsonFile)"
    Write-Host $response
    

    【讨论】:

    • 感谢您的 sn-p,我最终做了类似的事情。在添加进一步的支持之前必须这样做!
    【解决方案2】:

    不,您不能在 ARM 模板中创建索引。我之前读过的术语是 ARM 用于管理 Azure 控制平面。

    【讨论】:

      【解决方案3】:

      Azure 搜索目前不支持通过 ARM 模板管理索引。如果此功能对您很重要,请在User Voice 上添加项目以帮助我们确定优先级。

      【讨论】:

      • 感谢您的回答。目前它并不重要,因为有办法绕过它。
      猜你喜欢
      • 1970-01-01
      • 2017-10-17
      • 1970-01-01
      • 2020-03-03
      • 1970-01-01
      • 2019-07-29
      • 1970-01-01
      • 2021-05-24
      • 2023-03-11
      相关资源
      最近更新 更多