首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使用Kibana6.0或7+从控制台创建索引模式(v7.0.1)

使用Kibana6.0或7+从控制台创建索引模式(v7.0.1)
EN

Stack Overflow用户
提问于 2017-11-21 10:02:56
回答 4查看 10.9K关注 0票数 8

最近,我将我的ElasticStack实例从5.5升级到了6.0,并且这个版本的一些破坏似乎损害了我的管道。我有一个脚本,根据ElasticSearch内部的索引,为一些类似的索引组自动创建索引模式。问题是,随着6.0版本的新映射更改,我无法从控制台添加任何新的索引模式。这是我在5.5中使用并运行良好的请求:

代码语言:javascript
复制
curl -XPOST "http://localhost:9200/.kibana/index-pattern" -H 'Content-  Type: application/json' -d'
{
  "title" : "index_name",
  "timeFieldName" : "execution_time"
}'

这是我现在从ElasticSearch获得的在6.0中得到的响应:

代码语言:javascript
复制
{
  "error": {
    "root_cause": [
      {
        "type": "illegal_argument_exception",
        "reason": "Rejecting mapping update to [.kibana] as the final mapping would have more than 1 type: [index-pattern, doc]"
      }
    ],
    "type": "illegal_argument_exception",
    "reason": "Rejecting mapping update to [.kibana] as the final mapping would have more than 1 type: [index-pattern, doc]"
  },
  "status": 400
}

如何从控制台添加索引模式以避免这个多重映射问题?

EN

回答 4

Stack Overflow用户

发布于 2020-02-25 23:34:29

如果您是Kibana 7.0.1 / 7+,那么您可以引用saved_objects API : Refer:https://www.elastic.co/guide/en/kibana/master/saved-objects-api.html (查找Get、Create、Delete等)。

在本例中,我们将使用:https://www.elastic.co/guide/en/kibana/master/saved-objects-api-create.html

代码语言:javascript
复制
$ curl -X POST -u $user:$pass -H "Content-Type: application/json" -H "kbn-xsrf:true"  "${KIBANA_URL}/api/saved_objects/index-pattern/dummy_index_pattern" -d '{ "attributes": { "title":"index_name*", "timeFieldName":"sprint_start_date"}}'  -w "\n" | jq

代码语言:javascript
复制
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100   327  100   250  100    77    543    167 --:--:-- --:--:-- --:--:--   543
{
  "type": "index-pattern",
  "id": "dummy_index_pattern",
  "attributes": {
    "title": "index_name*",
    "timeFieldName": "sprint_start_date"
  },
  "references": [],
  "migrationVersion": {
    "index-pattern": "6.5.0"
  },
  "updated_at": "2020-02-25T22:56:44.531Z",
  "version": "Wzg5NCwxNV0="
}

$KIBANA_URL设置为:http://my-elk-stack.devops.local:5601

如果没有安装jq,请从命令中删除| jq (如上面所列)。

alpha-numeric PS:当Kibana的GUI用于创建index-pattern时,Kibana将其即索引ID存储为一个index-pattern值(ex: ,在执行GET操作以使用以下curl命令查找有关现有索引模式的信息时很难使用/查找/键入)。

如果您传递索引模式名称(就像我们前面所做的那样),那么在Kibana/Elasticsearch中,它将根据您给REST调用的名称( .../api/saved_objects/index-pattern/dummy_index_pattern") ex:)来描述索引模式的ID

这里:dummy_index_pattern将成为ID (只有当您在Kibana中的索引模式名称上悬停在鼠标上时,才能看到)和

它将有它的索引名为:index_name* (即当您单击Kibana Home > Gear icon > Index Patterns并看到右侧列出的索引模式时所列出的内容)。

备注:timeFieldName是非常重要的。这是一个字段,用于查找时间序列事件(特别是TSVB时间序列可视化类型)。默认情况下,它使用@timestamp字段,但是如果您每次重新创建索引(而不是每次从数据源(例如:JIRA)向目标Elasticsearch索引发送增量信息),并从数据源中一次性发送所有数据,那么@timestamp将无助于实现可视化的跨时间/窗口功能(您可以将时间从前1周更改为1小时或6个月);在这种情况下,您可以像我使用的那样设置一个不同的字段,即sprint_start_date (现在在Kibana页面中,如果您选择这个索引模式,它将对事件使用sprint_start_date (type: date)字段。

要获取有关新创建的索引模式的索引模式信息,可以参考:https://www.elastic.co/guide/en/kibana/master/saved-objects-api-get.html --或运行以下位置( URL路径中的最后一个值是我们前面创建的索引模式的ID值:

代码语言:javascript
复制
curl -X GET "${KIBANA_URL}/api/saved_objects/index-pattern/dummy_index_pattern" | jq

否则(如果您想在通过Kibana的GUI/Index Pattern > Create Index Pattern页面下创建的索引模式上执行一个Index Pattern > Create Index Pattern,您必须输入如下内容:

代码语言:javascript
复制
curl -X GET "${KIBANA_URL}/api/saved_objects/index-pattern/jqlaskl32ukdflsdjflskadf-sdf-sdfsaldkjfhsdf-dsfasdf" | jq 
票数 1
EN

Stack Overflow用户

发布于 2020-07-13 06:18:31

对于Kibana7.7.0和Open安全插件(准确地说,是amazon/opendistro-for-elasticsearch-kibana:1.8.0 Docker映像),这对我来说是有效的:

代码语言:javascript
复制
curl -X POST \
-u USERNAME:PASSWORD \
KIBANA_HOST/api/saved_objects/index-pattern \
-H "kbn-version: 7.7.0" \
-H "kbn-xsrf: true" \
-H "content-type: application/json; charset=utf-8" \
-d '{"attributes":{"title":"INDEX-PATTERN*","timeFieldName":"@timestamp","fields":"[]"}}'

请注意,kbn-xsrf头是必需的,但是从安全性的角度来看,它似乎是无用的。

产出如下:

代码语言:javascript
复制
{"type":"index-pattern","id":"UUID","attributes":{"title":"INDEX-PATTERN*","timeFieldName":"@timestamp","fields":"[]"},"references":[],"migrationVersion":{"index-pattern":"7.6.0"},"updated_at":"TIMESTAMP","version":"VERSION"}

我不知道为什么migrationVersion.index-pattern是"7.6.0“。

对于其他Kibana版本,您应该能够:

  1. 在浏览器中打开Kibana用户界面
  2. 打开开发人员控制台,导航到网络选项卡
  3. 使用UI创建索引模式
  4. 在开发人员控制台中打开POST请求,查看URL和标头,而不是将其重写到cURL
票数 1
EN

Stack Overflow用户

发布于 2017-11-21 11:50:23

在Elasticsearch 6.0.0或更高版本中创建的索引可能只包含单个映射类型。

在5.x中创建的具有多个映射类型的索引将继续像以前一样在Elasticsearch 6.x中工作。

映射类型将在Elasticsearch 7.0.0中完全删除。

也许您要在es6.0.0中创建一个具有多个doc_types的索引。https://www.elastic.co/guide/en/elasticsearch/reference/current/removal-of-types.html

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/47410250

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档