powershell - Powershell elasticsearch不起作用,缺少scrollId
问题描述
我正在创建一个 PowerShell 脚本来从公共服务中获取大量文件(我对此没有任何所有权)。我需要使用滚动 API 来获取我需要的所有文件,但我遇到了一个问题:在提供滚动 ID 时,Elasticsearch 使用邮递员和 PowerShell 做出不同的响应。
我已经在邮递员中手动重新创建了这些步骤,没有任何问题。
Function scrollBody ($scrollID) {
$scrollBody = @"
{
"scroll": "2m",
"scroll_id": "$scrollId"
}
"@
return $scrollBody
}
$body = (scrollBody `
-scrollID $scrollID
| ConvertFrom-Json)
$scrollUri = $ServerUri + "/_search/scroll"
$response = Invoke-WebRequest `
-Method GET `
-Uri $scrollUri `
-ContentType 'application/json' `
-Body $body `
| ConvertFrom-Json
我从代码的另一部分获得了工作滚动 ID,但我已经使用邮递员测试了这些 ID,它们工作正常。
我怀疑这是我提供身体的方式,但我遇到了这个错误:
{
"error": {
"root_cause": [
{
"type": "action_request_validation_exception",
"reason": "Validation Failed: 1: scrollId is missing;"
}
],
"type": "action_request_validation_exception",
"reason": "Validation Failed: 1: scrollId is missing;"
},
"status": 400
}
提前致谢
解决方案
我无法测试,但在调用函数以生成具有 scrollID 的对象时,您似乎遇到了语法错误。
您可以将其添加到请求的哈希中,这样会更容易阅读。反引号在某种程度上是一种反模式。
$serverUri = 'http://distribution.virk.dk/offentliggoerelser/_search/scroll'
$iwrParams = @{
'Uri' = $serverUri
'Method' = 'GET'
'ContentType' = 'applications/json'
'UseBasicParsing' = $true
'Body' = @{
'scroll' = '2m'
'scroll_id' = $scrollId
}
}
Invoke-WebRequest @iwrParams
推荐阅读
- nginx - 如何从主机中的浏览器访问虚拟机中的 URL
- python - 如何在 Python 中粘贴(如 R)和 groupby
- scanf - 多个分支上的 HP Fortify 扫描
- r - 有没有指定 geom_raster 插值范围的方法?
- ios - Swift:加载 /Library/Audio/Plug-Ins/HAL/NRDAudioClient 时出错:找不到合适的图像
- c# - IdentityUser 上的 AuditIgnore - Audit.Net
- mysql - Drupal 8 未连接到 Docker 中的 Mysql
- javascript - 使用 SAS 令牌从浏览器访问/更新 Azure Blob 存储是否安全?
- c# - 如何进行不和谐机器人登录并阅读特定服务器的消息以在 Windows 窗体应用程序中使用?
- angular6 - 有没有办法将 Angular 6 应用程序转换为库?