Skip to content

Do any type of query from a saved objects client #59408

@majagrubic

Description

@majagrubic

Some background:
When adding a visualization to the dashboard, we'd like to hide this visualization from the end user. From the end user perspective, this visualization doesn't exist in the Visualize app, but only in the context of the dashboard.

Plan:
To do that, I'd like to add a new flag to visualization saved object, called visible. All visualizations would have this flag set to true by default, except the ones created by the dashboard, which would have this set to false. If the flag is false, we wouldn't show this in the visualize listing. (Draft PR for the flow above)

Problem:
I thought that filtering items on the client side would be enough. This won't work in the saved objects management console, where we rely on the total number of hits in the ES response to do the pagination:


It could happen that ES finds 170 total saved objects, out of which 168 are visualizations, and out of those we only need to show 37, so the pagination would be messed up.

Which leads to changing the ES query itself. Query is issued through the saved_object_client.find method:

const findResponse = await savedObjectsClient.find({

which transforms the options to simple_query_string and looks on specific fields (ie. title).

"must": [
   {
     "simple_query_string":
        {
          "query": "bla*" ,
           "fields": ["config.title", "maps.title", "visualization.title"....]
         }
   }
]

Is there a way to make the saved object client accept any type of query?
I think the query I need would look something like:

{
  "query": {
    "bool": {
      "must": {
       "simple_query_string": {
         "query": "bla*"
       }
      },
      "should": [
        { "term": { "type": "visualization "}},
        { "term": { "type": "dashboard"}},
        { "term": { "type": "maps"}}
      ], 
      "must_not": {
        "term": { "visualization.visible": "false" }
      }
    }
  }
}

Alternatively, there's conditional clauses, but that can't be done through the client if I understand things correctly.

@pgayvallet suggest adding a visible field to all the saved objects as a mitigation for this issue, but it seems like an overkill for what I'm trying to do.

Would appreciate any ideas/thoughts/comments on how to proceed with this.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Team:CorePlatform Core services: plugins, logging, config, saved objects, http, ES client, i18n, etc t//discuss

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions