Skip to content

[Saved Objects Client] Allow sorting multiple types in the same find request #226160

@afharo

Description

@afharo

At the moment, it is not possible to sort the results of 2 Saved Object types in the same find request if the sorting field is not a root field.

if (types.length > 1) {
const rootField = getProperty(mappings, sortField);
if (!rootField) {
throw Boom.badRequest(
`Unable to sort multiple types by field ${sortField}, not a root property`
);
}

I believe that the underlying reason is that, even if the field name is the same (i.e.: name.keyword), they are actually persisted in ES as different fields (<type 1>.name.keyword, <type 2>.name.keyword), so sorting would be inaccurate.

I wonder if we could work around this limitation on ES by adding a runtime field that merges all fields

# Pseudo code
runtime_field.name.keyword = <type 1>.name.keyword ?? <type 2>.name.keyword

Then, we sort via the runtime field.

Use cases

This is mostly required by those SOs that needed to be duplicated when moving from agnostic to multi-space: #221568

Metadata

Metadata

Assignees

No one assigned

    Labels

    Feature:Saved ObjectsTeam:CoreCore services & architecture: plugins, logging, config, saved objects, http, ES client, i18n, etc

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions