Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Export-import Kibana [7.4] objects through saved_objects api

I am trying to move index patterns, visualizations and dashboards from one Kibana to another. They are running in separate dockers, listening to different ports. In the saved_objects API there are, import and export. Naively assuming that what export produces can be consumed by import I tried the code below:

import requests as req

header = {'Content-Type': 'application/json', 'kbn-xsrf': 'true'}

request_json_index_pattern = '''
{
  "type": "index-pattern"
}
'''

index_patterns = req.post(kibana_host+':5601/api/saved_objects/_export',
                    data=request_json_index_pattern,
                    headers = header,
                    auth = (elastic_user, elastic_password))


res = req.post(kibana_host+':5602/api/saved_objects/_import',
                    data=index_patterns.content,
                    headers = header,
                    auth = (elastic_user, elastic_password))



print(res.content)

But all I get is

{'statusCode': 415, 'error': 'Unsupported Media Type', 'message': 'Unsupported Media Type'}

All that, notwithstanding that index_patterns.content is a well-formatted ndjson– I can parsed it with ndjson.loads.

What am I missing?

(Btw, my source Kibana instance is 7.3.1 while the target is 7.4.0. Can that be the problem?)

like image 370
HerrIvan Avatar asked Sep 19 '26 01:09

HerrIvan


1 Answers

Ran into this myself. The _import API requires newline delimited json (ndjson), not json.

https://www.elastic.co/guide/en/kibana/current/saved-objects-api-import.html#_examples_3

A slightly hacky work-around that I found is to use the dashboards import api: /api/kibana/dashboards/import. It seems to import all saved objects types (not just dashboards).

like image 53
Ethan Strider Avatar answered Sep 20 '26 14:09

Ethan Strider