elasticsearch 如何在不使用Kibana UI的情况下将Kibana 6可视化导入elasticsearch 6?,elasticsearch,kibana,kibana-6,elasticsearch,Kibana,Kibana 6" /> elasticsearch 如何在不使用Kibana UI的情况下将Kibana 6可视化导入elasticsearch 6?,elasticsearch,kibana,kibana-6,elasticsearch,Kibana,Kibana 6" />

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

elasticsearch 如何在不使用Kibana UI的情况下将Kibana 6可视化导入elasticsearch 6?,elasticsearch,kibana,kibana-6,elasticsearch,Kibana,Kibana 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": "vis

我正在尝试将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中的存储对象,因此也不会显示在visualization选项卡上。当我使用“.kibana/doc/visualization:vis1”语法将其放入.kibana时,我的对象将显示在visualization选项卡上

现在,关于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\"}}"
  }
}
}
注意前几行。我从这个链接中发现,您必须修改json导出才能导入它。看起来很奇怪,对吧

无论如何,我在Kibana的实际可视化对象上有两个错误。第一个是“与此对象相关联的索引模式不再存在”。我可以通过创建一个索引模式来解决这个问题,该索引模式的id在可视化的searchSourceJson中引用。我必须在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索引中创建_类型索引模式的文档来完成此操作。

可以使用api通过kibana端点导入。
这需要修改导出的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\"}}"
    }
  }
}
'

所以这仍然会在Kibana UI中工作,它不会解决我的问题,但是我如何从visual1对象中判断哪些字段是重要的呢?它是“可视化”字段中的所有字段吗?因此,title、visState等……您需要确保在Kibana索引模式中存在的字段是visState.params.field中的元素。对于上面的示例,它看起来只是“principal.keyword”。我修改了答案,以提供如何在不使用web UI的情况下设置索引模式。