Using elasticsearch-py client to import dashboards

Hello,

I am trying to import a dashboard via the elasticsearch api with elastic search-py.

I have a sample dashboard from https://demo.elastic.co/ (the http one). I have exported it and it looks like this:

[
  {
    "_id": "HTTP",
    "_type": "dashboard",
    "_source": {
      "title": "HTTP",
      "hits": 0,
      "description": "",
      "panelsJSON": "[{\"col\":3,\"id\":\"Web-transactions\",\"row\":1,\"size_x\":10,\"size_y\":3,\"type\":\"visualization\"},{\"col\":1,\"id\":\"HTTP-error-codes\",\"row\":7,\"size_x\":6,\"size_y\":3,\"type\":\"visualization\"},{\"col\":7,\"id\":\"HTTP-error-codes-evolution\",\"row\":7,\"size_x\":6,\"size_y\":3,\"type\":\"visualization\"},{\"col\":1,\"id\":\"Navigation\",\"row\":1,\"size_x\":2,\"size_y\":3,\"type\":\"visualization\"},{\"col\":1,\"id\":\"Total-number-of-HTTP-transactions\",\"row\":4,\"size_x\":3,\"size_y\":3,\"type\":\"visualization\"},{\"col\":4,\"id\":\"HTTP-codes-for-the-top-queries\",\"row\":4,\"size_x\":9,\"size_y\":3,\"type\":\"visualization\"},{\"id\":\"Top-10-HTTP-requests\",\"type\":\"visualization\",\"size_x\":12,\"size_y\":5,\"col\":1,\"row\":10}]",
      "optionsJSON": "{\"darkTheme\":false}",
      "uiStateJSON": "{}",
      "version": 1,
      "timeRestore": false,
      "kibanaSavedObjectMeta": {
        "searchSourceJSON": "{\"filter\":[{\"query\":{\"query_string\":{\"analyze_wildcard\":true,\"query\":\"*\"}}}]}"
      }
    }
  }
]

I believe I should be using the create() member function in elastic-py. This was my function call that I was attempting.

with open('http.json') as data_file:
    data = json.load(data_file)
es.create(index='.kibana', id='http_dashboard', body=data)

however, I am getting http transport errors that were telling me that i could not have "hits" or "version", etc. how exactly can i import this dashboard via elasticsearch-py?

thanks in advance

ok so i have managed to successfully call create by modifying http.json as:

  {
    "type": "dashboard",
    "dashboard": {
      "title": "HTTP",
      "hits": 0,
      "description": "",
      "panelsJSON": "[{\"col\":3,\"id\":\"Web-transactions\",\"row\":1,\"size_x\":10,\"size_y\":3,\"type\":\"visualization\"},{\"col\":1,\"id\":\"HTTP-error-codes\",\"row\":7,\"size_x\":6,\"size_y\":3,\"type\":\"visualization\"},{\"col\":7,\"id\":\"HTTP-error-codes-evolution\",\"row\":7,\"size_x\":6,\"size_y\":3,\"type\":\"visualization\"},{\"col\":1,\"id\":\"Navigation\",\"row\":1,\"size_x\":2,\"size_y\":3,\"type\":\"visualization\"},{\"col\":1,\"id\":\"Total-number-of-HTTP-transactions\",\"row\":4,\"size_x\":3,\"size_y\":3,\"type\":\"visualization\"},{\"col\":4,\"id\":\"HTTP-codes-for-the-top-queries\",\"row\":4,\"size_x\":9,\"size_y\":3,\"type\":\"visualization\"},{\"id\":\"Top-10-HTTP-requests\",\"type\":\"visualization\",\"size_x\":12,\"size_y\":5,\"col\":1,\"row\":10}]",
      "optionsJSON": "{\"darkTheme\":false}",
      "uiStateJSON": "{}",
      "version": 1,
      "timeRestore": false,
      "kibanaSavedObjectMeta": {
        "searchSourceJSON": "{\"filter\":[{\"query\":{\"query_string\":{\"analyze_wildcard\":true,\"query\":\"*\"}}}]}"
      }
    }
  }

i see that the dashboard populates within the kibana gui, but when i click on it, i get an error that says "Could not locate that dashboard (id:http_dashboard)"

any ideas? is it because i did not import the visualizations that came along with this dashboard?

thank you

Directly posting to elasticsearch could be problematic (version, format, etc). Kibana has an API for import / export. I would recommend using this instead.

Thank you, this is helpful for getting all the required visualizations from a dashboard.

For demo purposes, i'm still using the http dashboard from https://demo.elastic.co/app/kibana.

I used the export api you mentioned: https://demo.elastic.co/api/kibana/dashboards/export?dashboard=HTTP

Although, it looks like this json still isn't compatible with the elasticsearch-py create() method. I'm getting the following error:

is there any way to inject multiple json objects with elasticsearch-py? otherwise i will still need to do some parsing by hand.

You would need to use a lower level library to do a direct request
(requests or urllib3) to kibana. The elasticsearch-py lib is for
interacting with elasticsearch, not kibana (although, not unreasonable for
you to make an enhancement request in that repo for interacting with kibana
as well).

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.