Kibana API: How to specify fields to be fetched in a GET call from saved_objects?

I'm trying to get list of Dashboards via API

http://localhost:5601/api/saved_objects/_find?type=dashboard&fields=id&fields=title

But this gives quite other fields (like references & type of visualizations etc), though I've specified fields required is just id & title.

eg BELOW is the current output, but I expected only "id" and "title" of from "dashboard" type

{
    "page": 1,
    "per_page": 20,
    "total": 2,
    "saved_objects": [
        {
            "type": "dashboard",
            "id": "7adfa750-4c81-11e8-b3d7-01146121b73d",
            "attributes": {
                "title": "[Flights] Global Flight Dashboard"
            },
            "references": [
                {
                    "name": "panel_0",
                    "id": "aeb212e0-4c84-11e8-b3d7-01146121b73d",
                    "type": "visualization"
                },
       ......

How to ensure that we receive ONLY the fields we specify in the GET call?

Hi there!

I believe the fields parameter only applies to the fields stored inside attributes. All other fields will always be returned. This should be clarified in our documentation.

EDIT: I've opened a pull request to update these docs: https://github.com/elastic/kibana/pull/71491

@joshdover
thanks for the explanation.
Any idea how to return Only the Required fields back? So I can display it into a table etc.

Our API will always return these base fields (id, attributes, references, etc.) and there is no way to limit that from the API side.

You'll need to do this in your application / script code. For instance, if you're in JavaScript you could do:

response.saved_objects.map(o => return { id: o.id, title: o.attributes.title });

If you're doing this on the command line, I recommend checking out the jq utility. Other than that, it just really depends on this is being consumed, but we have no feature for this in the API itself.

Hope that was helpful!

1 Like

thanks. Upvoted and made as solution.
Wished we had the ability to do the above javascript within Kibana :innocent:

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