Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support more powerful saved object filtering rules #17510

Closed
2 of 3 tasks
spalger opened this issue Apr 2, 2018 · 2 comments
Closed
2 of 3 tasks

Support more powerful saved object filtering rules #17510

spalger opened this issue Apr 2, 2018 · 2 comments
Assignees
Labels
discuss Meta Team:Core Core services & architecture: plugins, logging, config, saved objects, http, ES client, i18n, etc

Comments

@spalger
Copy link
Contributor

spalger commented Apr 2, 2018

Proposal: Support the filtering rules needed by the EUI SearchBar without coupling the effort to other DSL/AST/query lang initiatives by defining a basic filter schema that will allow basic boolean logic, filtering by terms, and ranges.

Example request body sent to POST /api/saved_objects/_find:

{
  experimental_filters: {
    must: [
      // numeric ranges
      { field: 'stars', gt: 3 },
      { field: 'followers', lte: 5 },

      // date ranges
      { field: 'created', gte: '2018-03-02T00:00:00-07:00', lt: '2018-03-03T00:00:00-07:00' },
      { field: 'created', gte: '2018-02-25T00:00:00-07:00', lt: '2018-03-01T00:00:00-07:00' },
      { field: 'created', lt: '2012-01-01T00:00:00-07:00' },

      // match, field not required
      { value: 'dashboard' },
      { field: 'active', value: true },

      // bools can be nested
      {
        must_some: [
          // today
          { field: 'created', gte: '2018-03-02T00:00:00-07:00', lt: '2018-03-03T00:00:00-07:00' },
          // yesterday
          { field: 'created', gte: '2018-03-01T00:00:00-07:00', lt: '2018-03-02T00:00:00-07:00' }
        ]
      }
    ],
    must_not: [
      { field: 'status', value: 'open' },
      { field: 'owner', value: 'dewey' },
      {
        must_some: [
          { field: 'tag', value: 'finance' },
          { field: 'tag', value: 'eng'  },
          { field: 'tag', value: 'ga'  }
        ]
      }
    ]
  }
}

Tasks:

@spalger spalger added discuss Team:Core Core services & architecture: plugins, logging, config, saved objects, http, ES client, i18n, etc Meta labels Apr 2, 2018
@spalger spalger self-assigned this Apr 2, 2018
@spalger
Copy link
Contributor Author

spalger commented Apr 2, 2018

With the current API we could determine the type of the filters without the type: property, but doing that would make for some really lame error messages if the type of the filter can't be determined.

For example, if the user sends:

{ valu: 'foo' }

Then the best error message we'll be able to provide is probably something like:

Unable to determine type of filter { valu: 'foo' }

If instead they sent:

{ type: 'match', valu: 'foo' }

We could really easily send:

invalid property 'valu', valid options are 'field' and 'value'

edit: switched back to implicit type to avoid noise, prevent advertising the name "match", and because the error message below is good enough for my taste

@spalger
Copy link
Contributor Author

spalger commented Apr 2, 2018

I'm going to switch back to no type: property and instead rely on an error message like:

invalid property 'valu'. possible properties are 'value', 'gt', 'gte', 'lt', 'lte', 'must', 'must_not', and 'must_some'

We can always add the type: property back if we need it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
discuss Meta Team:Core Core services & architecture: plugins, logging, config, saved objects, http, ES client, i18n, etc
Projects
None yet
Development

No branches or pull requests

1 participant