Tech Topics

How to Migrate to Kibana Spaces

Migrating to Spaces

Starting with Kibana 6.5, you can use Spaces to organize your dashboards, visualizations and other saved objects into categories. Additionally, when using security features, you're then able to control which roles are able to access which Space, allowing more users to use the same instance of Kibana with their own subset of saved objects.

When upgrading to a version of Kibana which supports Spaces, all of your existing saved objects will appear within the "Default" space. You're then able to move the objects between Spaces using one of the methods outlined below.

Moving a saved object between spaces

To move a saved object from one space to another, you can use the Import/Export UI in Kibana. It should be noted, that when moving a saved object using the Import/Export UI, its related saved objects aren't automatically moved. If you wish to move a dashboard and all its' dependencies between Spaces, see "Moving dashboards from one space to another".

For example, to move an index pattern from one space to another, go to Management > Saved Objects and then select the saved object that you'd like to move. When you click Export, you will be able to choose where to save the exported JSON.

Export Saved ObjectI

Then, use the Space selector to choose a different Space:

Change Space

Once you've changed your current Space, return to Management > Saved Objects. Each space's saved objects are entirely separate, so you won't see the index pattern that you just exported. To import the index pattern that you just exported, click Import and then browse to where you saved the JSON previously.

Import Saved Object

You'll now see the index pattern that you just imported show up. Even though we have two different index patterns, they'll be for the same underlying indices in Elasticsearch. Each space's saved objects are entirely separate, so any changes that you make to either index pattern won't affect the other Space's index pattern. If you no longer wish for the index pattern to be in the original space, you are now safe to delete it and it'll still be in the space you copied it to.

Consolidating multiple tenants to Spaces

If you're using multiple tenants of Kibana with their own Elasticsearch index to provide isolation for your Kibana users, you can use the Export/Import UI to consolidate to a single tenant using Spaces. To export all of your saved objects from a tenant, go to Management > Saved Objects, click the check-box in the header to select all objects, and click Export.

Export all Saved Objects

You will then be prompted where you'd like to save the JSON.

After you've exported the saved objects, go to the target instance of Kibana, create the target space if it doesn't exist and select the space. Go to Management > Saved Objects, and select Import and then locate the JSON file that you just saved. This will import all of the selected saved objects into a Space.

Moving dashboards from one space to another

Using the Import and Export UI in Kibana works well if you're moving individual saved objects, but it leaves a lot to be desired if you'd like to move a dashboard and all of its related visualizations, saved searches and index patterns. To move a dashboard to a different space, it's easiest to use the Dashboard Import/Export APIs.

Exporting the dashboard

To export a dashboard, we must first determine the dashboard's ID. Open up the dashboard that you'd like to export and if you inspect the URL, the long identifier between /app/kibana#/dashboard/ and the ? is it's ID. The dashboard ID has been highlighted in the following url:

http://localhost:5601/s/marketing/app/kibana#/dashboard/d203dd90-deac-11e8-869e-d73106bbd5ad?_g=()

Similarly, we'll also use the URL of the dashboard to determine the space URL identifier of the dashboard. The space URL identifier is included at the very start of the url between /s/ and /app/kibana#dashboard. If you don't see a /s/ in the url, then you're in the Default space. All urls in Kibana, including API urls, use a space prefix in the format of /s/{spaceID} to differentiate between spaces, except when we're dealing with the default space, and we don't use any prefix then. The space URL identifier has been highlighted in the following url:

http://localhost:5601/s/marketing/app/kibana#/dashboard/d203dd90-deac-11e8-869e-d73106bbd5ad?_g=()

Once we have the dashboard's ID, we can then execute a GET request against {spacePrefix}/api/kibana/dashboards/export?dashboard={dashboardID} using a similar CURL command to the following which will export a dashboard with ID d203dd90-deac-11e8-869e-d73106bbd5ad from the marketing space and save the dashboard and all of its dependencies to an export.json file:

curl -u elastic:changeme http://localhost:5601/s/marketing/api/kibana/dashboards/export?dashboard=d203dd90-deac-11e8-869e-d73106bbd5ad > export.json

Similarly, the following CURL command will export a dashboard with ID d203dd90-deac-11e8-869e-d73106bbd5ad from the default space and save it to an export.json file.

curl -u elastic:changeme http://localhost:5601/api/kibana/dashboards/export?dashboard=d203dd90-deac-11e8-869e-d73106bbd5ad > export.json

Importing the dashboard

Now that the hard part is done, we can import the dashboard into its new space. To do so, we'll once again have to determine the space URL identifier of the target space to construct the space prefix which appears in the URL. Using the space selector, select the target space where you'd like to move the Dashboard, and inspect the URL similarly to how we determined the space of the dashboard we'd like to export.

We can now execute a POST request to the {spacePrefix}/api/kibana/dashboards/import with the export.json we saved previously. The following CURL command will import the dashboard into the sales space:

curl -H "Content-Type: application/json" -H "kbn-xsrf: true" -u elastic:changeme http://localhost:5601/s/sales/api/kibana/dashboards/import --data-binary @export.json

Similarly, the following CURL command will import the dashboard into the default space:

curl -H "Content-Type: application/json" -H "kbn-xsrf: true" -u elastic:changeme http://localhost:5601/api/kibana/dashboards/import --data-binary @export.json

Once your dashboard is imported, if you no longer wish for it to exist in its original space, feel free to delete it.

Try it yourself

Kibana Spaces can be very helpful for decluttering and grouping your dashboards and visualizations. Whether it's allowing more users to use the same Kibana or used to implement a workflow, try it out yourself and let us know how you are leveraging Spaces.