我想使用Opensearch API创建一个索引模式。我遇到的问题是消息正文类型。运行脚本时收到以下消息
我在运行OpenSearch1.3
Invoke-RestMethod: {"statusCode":400,"error":"Bad Request","message":"[request body.attributes]: expected value of type [object] but got [undefined]"}
个字符
我尝试了各种方法来定义对象,但都没有成功。|convertfrom-json)我得到一个不同的错误消息。
Invoke-RestMethod: {"statusCode":400,"error":"Bad Request","message":"[request body]: expected a plain object value, but found [null] instead."}
型
最新消息:我最初确实尝试使用创建索引模式API来实现弹性,但这会导致创建一个新的索引,而不是一个opensearch index_pattern。
$body=@{
"index_pattern"= @{
"title"= "ai-summary"
}
}
$uri = "$baseuri/api/index_patterns/$indexid"
Invoke-RestMethod -Method Post -Uri $uri -Headers @{"osd-xsrf"="true"} -ContentType "application/json" -WebSession $S1 -Body ($body | ConvertTo-Json) -Verbose -Credential $credObject
型
1条答案
按热度按时间xn1cxnb41#
我认为问题在于,当使用
saved_objects
端点时,您需要在POST数据中使用"attributes"
而不是"index_pattern"
。(请注意您的错误消息,“[request body.attributes]:expected value of type [object] but got [undefined]"。)因此,您的body将是:字符串
我不熟悉您使用的语言,但类似以下shell脚本的东西对我有用(在OpenSearch 2.5下,但我相信它也可以在OpenSearch 1.3下工作)。
型
正如你所提到的,OpenSearch似乎不支持Kibana's
index_patterns
API。(或者至少我也不能让它工作。)我也不确定saved_objects
端点是否做了index_patterns
API所做的一切。至少当我使用OpenSearch Jmeter 板访问我创建的索引模式时,它会用索引的字段更新索引模式。