如何使用RESTful API在Kibana中导入/导出仪表板

5

我想使用HTTP方法将新的仪表板发布到我的本地Kibana实例,但是我在使用API时找不到太多相关文档。

Kibana上有一个拉请求(pull request)提到了它正在添加此功能,但是如何使用它的文档很少:https://github.com/elastic/kibana/pull/10858

这是我尝试发布的仪表板示例:

{ "_id": "12345678-1234-1234-1234-1234567890op", "_type": "dashboard", "_source": { "title": "my-app", "hits": 0, "description": "", "panelsJSON": "", "optionsJSON": "{\"darkTheme\":false}", "uiStateJSON": "", "version": 1, "timeRestore": true, "timeTo": "now/d", "timeFrom": "now/d", "refreshInterval": { "display": "1 minute", "pause": false, "section": 2, "value": 60000 }, "kibanaSavedObjectMeta": { "searchSourceJSON": "" } } }

2个回答

8

导出:

curl "localhost:5601/api/kibana/dashboards/export?dashboard=980381a0-a266-11e7-8f86-edd4a877426e" > export.json

{
  "version": "7.0.0-alpha1",
  "objects": [
    {
      "id": "12345678-1234-1234-1234-1234567890op",
      "type": "dashboard",
      "properties": {
        "title": "my-app",
        "hits": 0,
        "description": "",
        "panelsJSON": "",
        "optionsJSON": "{\"darkTheme\":false}",
        "uiStateJSON": "",
        "version": 1,
        "timeRestore": true,
        "timeTo": "now/d",
        "timeFrom": "now/d",
        "refreshInterval": {
          "display": "1 minute",
          "pause": false,
          "section": 2,
          "value": 60000
        }
      }
    }
  ]
}

导入:

将仪表板导出API的响应进行POST。

curl -X POST -H "Content-Type: application/json" -H "kbn-xsrf: true" -d @export.json http://localhost:5601/api/kibana/dashboards/import

0

@Tyler的答案完美地解决了我的问题。 我正在尝试将Java应用程序中的仪表板导入到Kibana中。在6.3.0上,以下操作运行良好:

HttpPost request = new HttpPost("http://localhost:5601/api/kibana/dashboards/import");
StringEntity params =new StringEntity(IMPORTED_JSON_STRING);
request.addHeader("content-type", "application/json");
request.addHeader("kbn-xsrf", "true");
request.setEntity(params);
HttpResponse response = httpClient.execute(request);

嗯,我认为仪表板API只在6.4及以上版本中才有。 - Nikolay Klimchuk

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接