【发布时间】:2019-05-16 12:34:37
【问题描述】:
我在 Azure DevOps 中有一个发布管道,它在标准 Azure 搜索服务上创建 36 个搜索索引,最多 50 个。
我正在使用一个 Powershell 脚本来读取存储库中的 json 文件,以直接使用 REST API 创建搜索索引。
首先我删除所有索引,然后重新创建它们。 (以满足存储在 repo 中的 json 文件的任何更改)
在出现以下错误之前,它似乎能够运行大约 25 次 REST API 调用:
(503) Server Unavailable. You are sending too many requests. Please try again later.
即使我在每个 REST API 调用之间插入 4 秒的延迟 (删除或创建索引)我仍然会收到相同的错误。
我有什么特别需要做的吗? REST API 调用率的限制是否记录在任何地方? (我以为here,但遗憾的是没有。)
Powershell 脚本片段是:($indexFiles 是要应用的 json 文件的列表)
$headers = @{"Content-Type" = "application/json"
"api-key" = $SearchAPIKey }
$indexesUrl = "https://$SearchSiteName.search.windows.net/indexes?api-version=$SearchAPIVersion"
Write-Host "Applying the following $($indexFiles.count) index files: "
$indexFiles | ForEach-Object { $indexData = Get-Content -Path $_.FullName -raw
$filename = $_.Name
try
{
Start-Sleep -Milliseconds $APICallDelay
$response = Invoke-WebRequest -Method Post -Uri $indexesUrl -Headers $headers -Body $indexData
if ($response.StatusCode -eq 201)
{
Write-Host "- $filename applied"
}
else
{
Write-Error "Issues with creating index $filename with Url $indexesUrl. Status code returned was $($response.StatusCode). Msg: $($response.StatusDescription)"
}
}
catch
{
$summaryMsg = $_.Exception.Message
$detailed = $_.ErrorDetails.Message | ConvertFrom-Json
$detailedMsg = $detailed.error.message
Write-Error "Error with creating index $filename. $summaryMsg. Detailed error: $detailedMsg"
}
}
如果有人能提供任何建议,将不胜感激!
【问题讨论】:
-
我发现的一种解决方法是仅调用 REST API 20 次,然后暂停 两分钟,然后再触发 20 次 REST API 调用并重复。虽然这确实有效,但速度很慢很烦人。希望有更好的方法来处理这个问题。
-
已获悉 Azure 搜索服务的当前限制: * 创建索引 (POST) 每分钟最多可调用 12 次 * 更新索引 (PUT) 每分钟最多可调用 360 次* 删除索引每分钟最多可以调用12次 * 获取索引每分钟最多可以调用600次 * 列表索引每分钟最多可以调用300次 所以目前,我们只能输入
Start-Sleep -Minutes 2在我们的代码中,如果我们一次部署超过 12 个索引。 :(
标签: powershell azure-cognitive-search