如何使用 API 在 Opensearch 中创建索引模式?
我想使用OpenSearch API创建索引模式。我尝试使用AS index模式名称 cwl-*在下面的图像窗口中以图形方式复制哪些内容,然后用作 time字段 @timestamp。 我的域已安装了OpenSearch 1.2。
使用curl(直接修改 kibana doc ):
curl -u '****:*****' -X POST "https://******.eu-central-1.es.amazonaws.com/api/index_patterns/index_pattern" -H 'osd-xsrf: true' -H 'Content-Type: application/json' -d'
{
"index_pattern": {
"title": "cwl-*",
"timeFieldName": "@timestamp"
}
}'
但是我收到
{"error":{"root_cause":[{"type":"illegal_argument_exception","reason":"Rejecting mapping update to [api] as the final mapping would have more than 1 type: [_doc, index_patterns]"}],"type":"illegal_argument_exception","reason":"Rejecting mapping update to [api] as the final mapping would have more than 1 type: [_doc, index_patterns]"},"status":400}
I want to create an index pattern using Opensearch API. I tried to replicate what could be made graphically in the following image window, using as index pattern name cwl-* and then as time field @timestamp.
My domain has OpenSearch 1.2 installed.
Using curl (directly modifiend the command in kibana doc):
curl -u '****:*****' -X POST "https://******.eu-central-1.es.amazonaws.com/api/index_patterns/index_pattern" -H 'osd-xsrf: true' -H 'Content-Type: application/json' -d'
{
"index_pattern": {
"title": "cwl-*",
"timeFieldName": "@timestamp"
}
}'
but I receive
{"error":{"root_cause":[{"type":"illegal_argument_exception","reason":"Rejecting mapping update to [api] as the final mapping would have more than 1 type: [_doc, index_patterns]"}],"type":"illegal_argument_exception","reason":"Rejecting mapping update to [api] as the final mapping would have more than 1 type: [_doc, index_patterns]"},"status":400}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
更改
api/index_patterns/index_pattern
toapi/index_patterns/cwl-*
,然后重试吗?change
api/index_patterns/index_pattern
toapi/index_patterns/cwl-*
and try again?当我在 URI 中添加 ID 并使用
saved_objects
而不是index_patterns
时,它在 OpenSearch 1.3 中对我有用。所以你的 cURL 请求应该像这样工作。
It worked for me in OpenSearch 1.3 when I added an ID in the URI and used
saved_objects
instead ofindex_patterns
.So your cURL-request should work when looking like this.
使用最新的 OpenSearch 版本 2.18.0 进行测试。
要通过 API 简单地创建索引模式,应使用 POST 请求:
如果您想创建具有特定 ID 的 OpenSearch 索引模式,您可以生成它或从其他源复制它(在我的例子中,我复制了 ID损坏的仪表板中丢失的模式)并将其作为请求的一部分包含:
如果您需要更新现有索引模式,则应使用 PUT 请求,并使用现有 ID:
Tested with the latest OpenSearch version 2.18.0.
To simply create an index pattern via the API, a POST request should be used:
If you want to create an OpenSearch index pattern with a specific ID, you can generate it or copy it from another source (in my case, I copied the ID of the missing pattern from the broken Dashboard) and include it as part of the request:
If you need to update existing index pattern, a PUT request should be used, with existing ID: