Kibana 6.4 - Script to import dashboards, visualisation, search and index

I exported all the dashboard, visualisation, search and index I wanted into a json file and wath I want is to have a script that import this json file like the import button in the saved object area

I looked lot of topic related to that but most of all are out of date since the big change of version 6 on Mapping Types https://logz.io/blog/removal-elasticsearch-mapping-types/ and this post https://github.com/elastic/kibana/pull/10858

I don't know if it's still possible with curl commands I tried things like this

curl -XPOST http://localhost:9200/myindexname/type/_bulk?pretty=true -H 'Content-Type: application/json' --data-binary @all-kibana-visu-6-4.json

but with not lot of success

1 Like

Hey @TheSmartMonkey, the endpoints for importing/exporting saved objects aren't publicly supported or documented yet, so while it's possible to reverse engineer the way that Kibana uses the internal APIs, they could potentially change between different versions.

With that being said, are you looking to export a Dashboard and all of it's related Visualizations, Searches and Index Patterns? If so, there's an internal API to do this which we use for loading Beats Dashboards which can be used similar to the following:

Export Dashboard

curl -k -XGET 'http://localhost:5601/api/kibana/dashboards/export?dashboard=<put your dashboard ID here>' -u elastic:changeme > export.json

Import Dashboard

curl -u elastic:changeme -k -XPOST 'http://localhost:5601/api/kibana/dashboards/import' -H 'Content-Type: application/json' -H "kbn-xsrf: true" -d @export.json
3 Likes

Thanks a lot for you help @Brandon_Kobel I share my script with the community hope that it will help some poeple :wink:
If my script can be better don't hesitate to comment

I export each of my dashboard 1 by 1 with this command :

curl -k -XGET 'http://localhost:5601/api/kibana/dashboards/export?dashboard=<put your dashboard ID here>' -u elastic:changeme > export.json

Then I did a python script to add all my dashboard, then to fix a default index pattern and finally to add index pattern that are not used in my dashboards

import os


kibana_url="localhost:5601/api/"

add_dashboard="curl -u elastic:changeme -k -XPOST 'http://"+kibana_url+"kibana/dashboards/import' -H 'Content-Type: application/json' -H \"kbn-xsrf: true\" -d @"

add_index="curl -f -XPOST -H 'Content-Type: application/json' -H 'kbn-xsrf: anything' '"+kibana_url+"saved_objects/index-pattern/"


#dashboard1
os.system(add_dashboard+"dashboard1.json")

#dashboard2
os.system(add_dashboard+"dashboard2.json")

#dashboard3
os.system(add_dashboard+"dashboard3.json")


#set "*" as default index
id_default_index="87f3bcc0-8b37-11e8-83be-afaed4786d8c"

os.system("curl -X POST -H \"Content-Type: application/json\" -H \"kbn-xsrf: true\" -d '{\"value\":\""+id_default_index+"\"}' http://elastic:changeme@"+kibana_url+"kibana/settings/defaultIndex")


#Create index pattern
index_name = "index1-*"
os.system(add_index+index_name+"' '-d{\"attributes\":{\"title\":\""+index_name+"\",\"timeFieldName\":\"@timestamp\"}}'")

index_name = "index2-*"
os.system(add_index+index_name+"' '-d{\"attributes\":{\"title\":\""+index_name+"\",\"timeFieldName\":\"@timestamp\"}}'")

index_name = "index3-*"
os.system(add_index+index_name+"' '-d{\"attributes\":{\"title\":\""+index_name+"\",\"timeFieldName\":\"@timestamp\"}}'")

index_name = "index4-*"
os.system(add_index+index_name+"' '-d{\"attributes\":{\"title\":\""+index_name+"\",\"timeFieldName\":\"@timestamp\"}}'")

index_name = "index5-*"
os.system(add_index+index_name+"' '-d{\"attributes\":{\"title\":\""+index_name+"\",\"timeFieldName\":\"@timestamp\"}}'")
2 Likes

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