How to import/export a dashboard in Kibana using a RESTful API

Deadly 提交于 2020-01-02 06:29:12

问题


I would like to use a HTTP method to post new dashboards to my local Kibana instance, but I couldn't find much documentation on using an API to do this.

There was a pull request on Kibana that mentioned it was adding this functionality, but there was limited documentation on how to use it: https://github.com/elastic/kibana/pull/10858

An example of a dashboard I'm trying to post:

{ "_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": "" } } }


回答1:


Export:

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
        }
      }
    }
  ]
}

Import:

POST the response from the dashboard export API.

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



回答2:


@Tyler answer worked perfectly. I was trying to import dashboards from Java app to Kibana. Following worked fine on 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);


来源:https://stackoverflow.com/questions/47017583/how-to-import-export-a-dashboard-in-kibana-using-a-restful-api

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!