Importing multiple index patterns in kibana 6

Hello there,
I have a production system whereby each tenant is assigned dedicated aliases for reporting purposes. I can't change this approach. When a new tenant is added to the system, then from a kibana perspective I need to import a new set of index patterns for these aliases and a new set of set of dashboards (and their dependencies: visualizations and saved searches) particular to this new tenant.

In Kibana 5 this task was achieved by writing directly to the .kibana index through elastic-search client. However, I'm sure the recommended approach in Kibana 6 is to do this via the Kibana APIs. I've been following:

how-to-import-index-pattern-in-kibana-6-using-api

API for managing saved objects

I exported a set of index patterns with something like:
curl -uelastic --insecure "https://localhost:5602/api/saved_objects?type=index-pattern" >> index_patterns.json

However, once I have an array of index-pattern objects I don't know how to import them. I've tried the following:

[tango@iel-dev-mtn-vm2 experimental]$ curl -uelastic:t3l3com --insecure -X POST -H "Content-Type: application/json" -H "kbn-xsrf: true" "https://diffhost:5602/api/saved_objects/index-pattern" -d "@master_index_patterns.json"
{"statusCode":400,"error":"Bad Request","message":""value" must be an object","validation":{"source":"payload","keys":["value"]}}
[tango@iel-dev-mtn-vm2 experimental]$

As the object is an array of objects, I tried wrapping the array in an object { "objects" : []}, as I've observed this pattern in some other kibana APIs.

[tango@iel-dev-mtn-vm2 experimental]$ curl -uelastic --insecure -X POST -H "Content-Type: application/json" -H "kbn-xsrf: true" "https://diffhost:5602/api/saved_objects/index-pattern" -d "@master_index_patterns.json"
{"statusCode":400,"error":"Bad Request","message":"child "attributes" fails because ["attributes" is required]. "objects" is not allowed","validation":{"source":"payload","keys":["attributes","objects"]}}[

Any guidance on how to proceed would be very much appreciated.

We changed the way that documents are structured internally when switching from 5.0 to 6.0 as Elasticsearch dropped support for multiple types in the same index.Unfortunately we don't have a supported and future proof way of doing what you need; however, there is an internal APIs that we use for importing/exporting objects. These internal APIs should isolate you from the internal structure of the documents in the .kibana index and be more future proof between versions.

/api/kibana/dashboards/export and /api/kibana/dashboards/export work with Dashboards and all of their related visualizations. Unfortunately, these aren't documented but you should be able to play around with them and get them to work. These APIs are considered "internal" and are subject to change in minor versions, so you should make sure that you test your integration with every minor release.

Thanks Brandon for your response.
For anyone else landing here, this is what I did.
I manually created the index patterns I needed from Kibana UI. Then from Kibana UI I imported my dashboards (and their dependent visualizations and saved searches) not including any index patterns. My understanding is that I cannot import index patterns from the front-end.

The I export each individual dashboard from /api/kibana/dashboards/export, for each of my dashboards. Now I have a dashboard object with all its dependencies including index patterns. I manually put all these objects in a file, where each dashboard object is put in a JSON array. I templated the file with a tenantId for substitution later, and then I wrote a python script to iterate through the array and call /api/kibana/dashboards/import on a clean Kibana instance.

One potential improvement might be to support and import all button that works with the output of export all which would include support for index-pattern as a dashboard dependency.

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