Andrew Mercer
on this page

Export everything in one file

curl -sS --fail -X POST "$KIBANA_URL/api/saved_objects/_export" \
  -H "Authorization: ApiKey $ES_API_KEY" \
  -H 'kbn-xsrf: true' \
  -H 'Content-Type: application/json' \
  -d '{
        "type": ["dashboard", "visualization", "lens", "map", "search",
                 "index-pattern", "query", "tag", "url"],
        "includeReferencesDeep": true
      }' \
  -o "kibana-saved-objects-$(date +%F).ndjson"
  • includeReferencesDeep pulls in everything a dashboard depends on (visualizations, data views), so the file can be restored on its own.
  • The last line of the file is an export summary (exportedCount, missingRefCount). Check missingRefCount is 0.
  • The export is capped by Kibana's savedObjects.maxImportExportSize (default 10,000 objects).

One file per type

This is useful for diffs in git, or for finding which type is failing:

types=(dashboard visualization lens map search index-pattern query tag url)

for type in "${types[@]}"; do
  if curl -sS --fail -X POST "$KIBANA_URL/api/saved_objects/_export" \
       -H "Authorization: ApiKey $ES_API_KEY" \
       -H 'kbn-xsrf: true' -H 'Content-Type: application/json' \
       -d "{\"type\": \"${type}\", \"includeReferencesDeep\": true}" \
       -o "${type}.ndjson"; then
    echo "ok      ${type} ($(($(wc -l < "${type}.ndjson") - 1)) objects)"
  else
    echo "FAILED  ${type}"
  fi
done

Each space exports separately. Prefix the path with /s/<space_id> for spaces other than the default one.

Restore

curl -sS -X POST "$KIBANA_URL/api/saved_objects/_import?overwrite=true" \
  -H "Authorization: ApiKey $ES_API_KEY" \
  -H 'kbn-xsrf: true' \
  -F file=@kibana-saved-objects-[ date ].ndjson | jq '{success, successCount, errors}'