Using Kibana API, How do I query for all dashboards including its related spaces

According to the Kibana API doc, I can query for all dashboards using

curl -u user:pwd -X GET 'https://kibana.elastic-cloud.com:9243/api/saved_objects/_find?type=dashboard'

and I can query for all spaces using

curl -u user:pwd -X GET 'https://kibana.elastic-cloud.com:9243/api/spaces/space'

and I can query for all dashboards within a space using

curl -u user:pwd -X GET 'https://kibana.elastic-cloud.com:9243/s/my_spaces_name/api/saved_objects/_find?type=dashboard'

BUT if i wanted to query for ALL dashboards in Elasticsearch AND cross-reference each dashboard in result with a possible related spaces? I can figure out how to do this by

  1. Query all Spaces
  2. Iterate over each spaces in result, and query each space for child Dashboards
  3. Query All Dashboards globally
  4. Merge the two results

There MUST be a better, more time/resource efficient way to perform this?

Much thanks

That is pretty much the only way possible.

Thank you for responding

For anyone else reading this Topic.

What I now understand is that;

Though dashboard can share the same Doc ID (since it would have been copied from the Default Space into a separate more restricted Space using export/import in Saved Objects)

The reality is that both dashboards (in separate spaces) are completely independent of each other, can diverge quite greatly from each other and therefore no merging need to take place.

When I query ALL dashboards (without specifying a spaces) I am actually querying dashboards in the DEFAULT space, "independently" of any dashboards with the same ID that I might come across when I query dashboards in each Space container.

In short, no merging needs to be done (Step 4 is unnecessary) therefore saving some middle-ware processing.

Hope this helps someone else