如何在不使用 Kibana UI 的情况下将 Kibana 6 可视化导入 elasticsearch 6?



我正在尝试将 Kibana 6 可视化导入 Elasticsearch 6,以便在 Kibana 中查看。 我正在尝试使用 curl 命令或本质上是一个脚本来执行此操作,而无需通过 Kibana UI。 这是我正在使用的命令:

curl -XPUT http://localhost:9200/.kibana/doc/visualization:vis1 -H 
'Content-Type: application/json' -d @visual1.json

这是visual1.json:

{
"type": "visualization",
"visualization": {
"title": "Logins",
"visState": "{"title":"Logins","type":"histogram","params":{"type":"histogram","grid":{"categoryLines":false,"style":{"color":"#eee"}},"categoryAxes":[{"id":"CategoryAxis-1","type":"category","position":"bottom","show":true,"style":{},"scale":{"type":"linear"},"labels":{"show":true,"truncate":100},"title":{}}],"valueAxes":[{"id":"ValueAxis-1","name":"LeftAxis-1","type":"value","position":"left","show":true,"style":{},"scale":{"type":"linear","mode":"normal"},"labels":{"show":true,"rotate":0,"filter":false,"truncate":100},"title":{"text":"Count"}}],"seriesParams":[{"show":"true","type":"histogram","mode":"stacked","data":{"label":"Count","id":"1"},"valueAxis":"ValueAxis-1","drawLinesBetweenPoints":true,"showCircles":true}],"addTooltip":true,"addLegend":true,"legendPosition":"right","times":[],"addTimeMarker":false},"aggs":[{"id":"1","enabled":true,"type":"count","schema":"metric","params":{}},{"id":"2","enabled":true,"type":"terms","schema":"segment","params":{"field":"principal.keyword","otherBucket":true,"otherBucketLabel":"Other","missingBucket":false,"missingBucketLabel":"Missing","size":5,"order":"desc","orderBy":"1"}}]}",
"uiStateJSON": "{}",
"description": "",
"version": 1,
"kibanaSavedObjectMeta": {
"searchSourceJSON": "{"index":"def097e0-550f-11e8-9266-93ce640e5839”,”filter":[{"meta":{"index":"def097e0-550f-11e8-9266-93ce640e5839”,”negate":false,"disabled":false,"alias":null,"type":"phrase","key":"requestType.keyword","value":"ALOG”,”params":{"query":"AUTH_LOGIN","type":"phrase"}},"query":{"match":{"requestType.keyword":{"query":"AUTH_LOGIN","type":"phrase"}}},"$state":{"store":"appState"}}],"query":{"query":"","language":"lucene"}}"
}
}
}

现在需要注意有关 curl 命令和此 json 文件的几件事。 我将可视化推送到的索引是 .kibana。 我发现当我将这些推送到其他索引(如"test"(时,我的数据不会在 Kibana 中显示为存储对象,因此不会显示在可视化选项卡上。 当我使用此语法".kibana/doc/visualization:vis1"放入.kibana时,我的对象显示在可视化选项卡上。

现在关于 json 文件。 请注意,当您从 Kibana 6 导出可视化时,它看起来不像这样。 它看起来像:

{
"_id": "vis1",
"_type": "visualization",
"_source": {
"title": "Logins",
"visState": "{"title":"Logins","type":"histogram","params":{"type":"histogram","grid":{"categoryLines":false,"style":{"color":"#eee"}},"categoryAxes":[{"id":"CategoryAxis-1","type":"category","position":"bottom","show":true,"style":{},"scale":{"type":"linear"},"labels":{"show":true,"truncate":100},"title":{}}],"valueAxes":[{"id":"ValueAxis-1","name":"LeftAxis-1","type":"value","position":"left","show":true,"style":{},"scale":{"type":"linear","mode":"normal"},"labels":{"show":true,"rotate":0,"filter":false,"truncate":100},"title":{"text":"Count"}}],"seriesParams":[{"show":"true","type":"histogram","mode":"stacked","data":{"label":"Count","id":"1"},"valueAxis":"ValueAxis-1","drawLinesBetweenPoints":true,"showCircles":true}],"addTooltip":true,"addLegend":true,"legendPosition":"right","times":[],"addTimeMarker":false},"aggs":[{"id":"1","enabled":true,"type":"count","schema":"metric","params":{}},{"id":"2","enabled":true,"type":"terms","schema":"segment","params":{"field":"principal.keyword","otherBucket":true,"otherBucketLabel":"Other","missingBucket":false,"missingBucketLabel":"Missing","size":5,"order":"desc","orderBy":"1"}}]}",
"uiStateJSON": "{}",
"description": "",
"version": 1,
"kibanaSavedObjectMeta": {
"searchSourceJSON": "{"index":"def097e0-550f-11e8-9266-93ce640e5839","filter":[{"meta":{"index":"def097e0-550f-11e8-9266-93ce640e5839","negate":false,"disabled":false,"alias":null,"type":"phrase","key":"requestType.keyword","value":"LOG","params":{"query":"LOG","type":"phrase"}},"query":{"match":{"requestType.keyword":{"query":"LOG","type":"phrase"}}},"$state":{"store":"appState"}}],"query":{"query":"","language":"lucene"}}"
}
}
}

请注意前几行。 我从这个链接中发现无法在 elaticearch 中使用 curl 命令创建可视化,您必须修改 json 导出才能导入它。 看起来很奇怪吧?

无论如何,我在 Kibana 中一次在实际可视化对象上遇到了两个错误。 第一个是"与此对象关联的索引模式不再存在"。 我能够通过使用可视化的 searchSourceJson 中引用的 id 创建一个索引模式来解决这个问题。 我必须在 Kibana UI 中执行此操作,因此从技术上讲,此解决方案不适合我。 无论如何,我通过调用创建了一个包含文档的索引

curl -X PUT "localhost:9200/test57/_doc/1" -H 'Content-Type: application/json' -d'
{
"user" : "kimchy",
"post_date" : "2009-11-15T14:12:12",
"message" : "trying out Elasticsearch"
}
'

然后在 Kibana UI 中,创建了一个索引模式,并为其提供了自定义索引模式 ID def097e0-550f-11e8-9266-93ce640e5839。

现在,当我尝试查看我的可视化时,我收到一个新错误。 "与此对象关联的字段不再存在于索引模式中。">
我猜这与我将随机对象推送到索引中有关,但即使为 elastic 和 kibana 打开了调试设置,我也没有真正获得足够的信息来解决这个问题。

如果有人能指出我正确的方向,那就太好了! 提前谢谢。

您需要确保可视化定义中引用的字段也存在于 Kibana 索引模式中(>管理>索引模式的 Kibana 主屏幕(。 最简单的方法是将所述字段包含在您创建的虚拟索引中,然后在 Kibana 索引模式屏幕中"刷新字段列表"。

您可以通过 CLI 在 .kibana 索引中创建索引模式_type文档来执行此操作。

可以使用api 通过 kibana 端点导入 saved_objects.
这需要修改导出的 json 将其包装在{"attributes":....}

根据您的示例,它应该是这样的:

curl -XPOST "http://localhost:5601/api/saved_objects/visualization/myvisualisation?overwrite=true" -H "kbn-xsrf: reporting" -H 'Content-Type: application/json' -d'
{"attributes":{
"title": "Logins",
"visState": "{"title":"Logins","type":"histogram","params":{"type":"histogram","grid":{"categoryLines":false,"style":{"color":"#eee"}},"categoryAxes":[{"id":"CategoryAxis-1","type":"category","position":"bottom","show":true,"style":{},"scale":{"type":"linear"},"labels":{"show":true,"truncate":100},"title":{}}],"valueAxes":[{"id":"ValueAxis-1","name":"LeftAxis-1","type":"value","position":"left","show":true,"style":{},"scale":{"type":"linear","mode":"normal"},"labels":{"show":true,"rotate":0,"filter":false,"truncate":100},"title":{"text":"Count"}}],"seriesParams":[{"show":"true","type":"histogram","mode":"stacked","data":{"label":"Count","id":"1"},"valueAxis":"ValueAxis-1","drawLinesBetweenPoints":true,"showCircles":true}],"addTooltip":true,"addLegend":true,"legendPosition":"right","times":[],"addTimeMarker":false},"aggs":[{"id":"1","enabled":true,"type":"count","schema":"metric","params":{}},{"id":"2","enabled":true,"type":"terms","schema":"segment","params":{"field":"principal.keyword","otherBucket":true,"otherBucketLabel":"Other","missingBucket":false,"missingBucketLabel":"Missing","size":5,"order":"desc","orderBy":"1"}}]}",
"uiStateJSON": "{}",
"description": "",
"version": 1,
"kibanaSavedObjectMeta": {
"searchSourceJSON": "{"index":"def097e0-550f-11e8-9266-93ce640e5839","filter":[{"meta":{"index":"def097e0-550f-11e8-9266-93ce640e5839","negate":false,"disabled":false,"alias":null,"type":"phrase","key":"requestType.keyword","value":"LOG","params":{"query":"LOG","type":"phrase"}},"query":{"match":{"requestType.keyword":{"query":"LOG","type":"phrase"}}},"$state":{"store":"appState"}}],"query":{"query":"","language":"lucene"}}"
}
}
}
'

最新更新