如何使用 API 在 Opensearch 中创建索引模式?

发布于 2025-01-20 06:00:22 字数 1153 浏览 0 评论 0原文

我想使用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.

enter image description here

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

绮烟 2025-01-27 06:00:22
curl -u '****:*****' -X POST "https://******.eu-central-1.es.amazonaws.com/api/index_patterns/cwl-*" -H 'osd-xsrf: true' -H 'Content-Type: application/json' -d'
{
  "index_pattern": {
     "title": "cwl-*",
     "timeFieldName": "@timestamp"
  }
}'

更改api/index_patterns/index_pattern to api/index_patterns/cwl-*,然后重试吗?

curl -u '****:*****' -X POST "https://******.eu-central-1.es.amazonaws.com/api/index_patterns/cwl-*" -H 'osd-xsrf: true' -H 'Content-Type: application/json' -d'
{
  "index_pattern": {
     "title": "cwl-*",
     "timeFieldName": "@timestamp"
  }
}'

change api/index_patterns/index_pattern to api/index_patterns/cwl-* and try again?

﹂绝世的画 2025-01-27 06:00:22

当我在 URI 中添加 ID 并使用 saved_objects 而不是 index_patterns 时,它在 OpenSearch 1.3 中对我有用。

所以你的 cURL 请求应该像这样工作。

curl -u '****:*****' -X POST "https://<opensearch-dashboards-host>.eu-central-1.es.amazonaws.com/api/saved_objects/index-pattern/<ID>" 
-H 'osd-xsrf: true' 
-H 'Content-Type: application/json' 
-d 
   '{
      "index_pattern": {
         "title": "cwl-*",
         "timeFieldName": "@timestamp"
      }
    }'

It worked for me in OpenSearch 1.3 when I added an ID in the URI and used saved_objects instead of index_patterns.

So your cURL-request should work when looking like this.

curl -u '****:*****' -X POST "https://<opensearch-dashboards-host>.eu-central-1.es.amazonaws.com/api/saved_objects/index-pattern/<ID>" 
-H 'osd-xsrf: true' 
-H 'Content-Type: application/json' 
-d 
   '{
      "index_pattern": {
         "title": "cwl-*",
         "timeFieldName": "@timestamp"
      }
    }'
心意如水 2025-01-27 06:00:22

使用最新的 OpenSearch 版本 2.18.0 进行测试。

要通过 API 简单地创建索引模式,应使用 POST 请求:

    curl -XPOST "http://localhost:5601/api/saved_objects/index-pattern" \
-u "user:pass" \
-H 'osd-xsrf: true' \
-H 'Content-Type: application/json' \
-d ' 
{
  "attributes": {
    "title": "pattern-*",
    "timeFieldName": "@timestamp"
  }
}'

如果您想创建具有特定 ID 的 OpenSearch 索引模式,您可以生成它或从其他源复制它(在我的例子中,我复制了 ID损坏的仪表板中丢失的模式)并将其作为请求的一部分包含:

curl -XPOST "http://localhost:5601/api/saved_objects/index-pattern/90bd9a00-ad57-41a0-b16a-b134a8c51e98" \
-u "user:pass" \
-H 'osd-xsrf: true' \
-H 'Content-Type: application/json' \
-d ' 
{
  "attributes": {
    "title": "pattern-*",
    "timeFieldName": "@timestamp"
  }
}'

如果您需要更新现有索引模式,则应使用 PUT 请求,并使用现有 ID:

curl -XPUT "http://localhost:5601/api/saved_objects/index-pattern/90bd9a00-ad57-41a0-b16a-b134a8c51e98" \
-u "user:pass" \
-H 'osd-xsrf: true' \
-H 'Content-Type: application/json' \
-d ' 
{
  "attributes": {
    "title": "pattern-*",
    "timeFieldName": "@timestamp"
  }
}'

Tested with the latest OpenSearch version 2.18.0.

To simply create an index pattern via the API, a POST request should be used:

    curl -XPOST "http://localhost:5601/api/saved_objects/index-pattern" \
-u "user:pass" \
-H 'osd-xsrf: true' \
-H 'Content-Type: application/json' \
-d ' 
{
  "attributes": {
    "title": "pattern-*",
    "timeFieldName": "@timestamp"
  }
}'

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:

curl -XPOST "http://localhost:5601/api/saved_objects/index-pattern/90bd9a00-ad57-41a0-b16a-b134a8c51e98" \
-u "user:pass" \
-H 'osd-xsrf: true' \
-H 'Content-Type: application/json' \
-d ' 
{
  "attributes": {
    "title": "pattern-*",
    "timeFieldName": "@timestamp"
  }
}'

If you need to update existing index pattern, a PUT request should be used, with existing ID:

curl -XPUT "http://localhost:5601/api/saved_objects/index-pattern/90bd9a00-ad57-41a0-b16a-b134a8c51e98" \
-u "user:pass" \
-H 'osd-xsrf: true' \
-H 'Content-Type: application/json' \
-d ' 
{
  "attributes": {
    "title": "pattern-*",
    "timeFieldName": "@timestamp"
  }
}'
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文