-
Notifications
You must be signed in to change notification settings - Fork 8.5k
[Dashboards as code] Define schemas for API filter interface #241198
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
Open
nickpeihl
wants to merge
5
commits into
elastic:main
Choose a base branch
from
nickpeihl:simple-filters-schema
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+333
−2
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
|
Pinging @elastic/kibana-presentation (Team:Presentation) |
|
Pinging @elastic/kibana-data-discovery (Team:DataDiscovery) |
|
Pinging @elastic/kibana-visualizations (Team:Visualizations) |
7f78e6a to
5037bbe
Compare
💔 Build Failed
Failed CI StepsHistory |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
backport:skip
This PR does not require backporting
Project:Dashboards API
release_note:skip
Skip the PR/issue when compiling release notes
Team:DataDiscovery
Discover, search (data plugin and KQL), data views, saved searches. For ES|QL, use Team:ES|QL. t//
Team:Presentation
Presentation Team for Dashboard, Input Controls, and Canvas t//
Team:Visualizations
Team label for Lens, elastic-charts, Graph, legacy editors (TSVB, Visualize, Timelion) t//
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Part of #237535
Summary
Introduce validation schemas for an API Filter interface in the
@kbn/es-query-serverpackage, enabling "* as Code" API consumers to work with filters using a human-readable, type-safe format instead of the complex and weakly typedFilterinterface that is currently stored.The current
Filterinterface, while extensible, is unsuitable for "* as Code" API consumers:meta.key,meta.field,meta.params) that duplicates information already in the query$stateRecord<string, any>in query structuresAdvantages
Our proposed API Filter schema offers more advantages for API consumers:
value, range filters requireRangeValue)@kbn/config-schemapackageReviewer notes
This PR only introduces new schemas and does not make any behavioral changes to code. Subsequent PRs will be created:
Technical details
Schema structure
introduces discriminated union schemas ensuring exactly one of:
See Examples below
Validation benefits
@kbn/config-schemavalidates input at API boundariesExamples of the new API filter schemas compared to the legacy filter
API Filter
Legacy format
{ "$state": { "store": "appState" }, "meta": { "alias": null, "disabled": false, "negate": false, "key": "host.keyword", "field": "host.keyword", "type": "phrase", "params": { "query": "www.elastic.co" }, "index": "90943e30-9a47-11e8-b64d-95841ca0b247" }, "query": { "match_phrase": { "host.keyword": "www.elastic.co" } } }API format
{ "pinned": false, "disabled": false, "dataViewId": "90943e30-9a47-11e8-b64d-95841ca0b247", "negate": false, "condition": { "field": "host.keyword", "operator": "is", "value": "www.elastic.co" } }Grouped filter
Legacy format
[ { "meta": { "type": "combined", "relation": "AND", "params": [ { "query": { "match_phrase": { "host.keyword": "www.elastic.co" } }, "meta": { "negate": false, "key": "host.keyword", "field": "host.keyword", "type": "phrase", "params": { "query": "www.elastic.co" }, "index": "90943e30-9a47-11e8-b64d-95841ca0b247", "disabled": false } }, { "meta": { "negate": true, "index": "90943e30-9a47-11e8-b64d-95841ca0b247", "key": "machine.os.keyword", "field": "machine.os.keyword", "params": [ "ios", "osx" ], "value": [ "ios", "osx" ], "type": "phrases", "disabled": false }, "query": { "bool": { "minimum_should_match": 1, "should": [ { "match_phrase": { "machine.os.keyword": "ios" } }, { "match_phrase": { "machine.os.keyword": "osx" } } ] } } } ], "disabled": false, "negate": false, "alias": null, "index": "90943e30-9a47-11e8-b64d-95841ca0b247" }, "query": {}, "$state": { "store": "appState" } } ]API format
[ { "pinned": false, "disabled": false, "dataViewId": "90943e30-9a47-11e8-b64d-95841ca0b247", "negate": false, "group": { "type": "AND", "conditions": [ { "field": "host.keyword", "operator": "is", "value": "www.elastic.co" }, { "type": "OR", "conditions": [ { "field": "machine.os.keyword", "operator": "is_not", "value": "ios" }, { "field": "machine.os.keyword", "operator": "is_not", "value": "osx" } ] } ] } } ]Nested group filter
Legacy format
[ { "$state": { "store": "appState" }, "meta": { "alias": "My nested filter", "disabled": false, "negate": false, "type": "combined", "relation": "AND", "params": [ { "query": { "match_phrase": { "host.keyword": "www.elastic.co" } }, "meta": { "index": "90943e30-9a47-11e8-b64d-95841ca0b247", "negate": false, "key": "host.keyword", "field": "host.keyword", "type": "phrase", "params": { "query": "www.elastic.co" } } }, { "meta": { "index": "90943e30-9a47-11e8-b64d-95841ca0b247", "negate": false, "type": "combined", "relation": "OR", "params": [ { "query": { "match_phrase": { "index.keyword": "kibana_sample_data_logs" } }, "meta": { "index": "90943e30-9a47-11e8-b64d-95841ca0b247", "negate": false, "key": "index.keyword", "field": "index.keyword", "type": "phrase", "params": { "query": "kibana_sample_data_logs" } } }, { "query": { "bool": { "should": [ { "match_phrase": { "extension.keyword": "css" } }, { "match_phrase": { "extension.keyword": "gz" } } ], "minimum_should_match": 1 } }, "meta": { "index": "90943e30-9a47-11e8-b64d-95841ca0b247", "negate": false, "key": "extension.keyword", "type": "phrases", "params": [ "css", "gz" ] } } ] } } ], "index": "90943e30-9a47-11e8-b64d-95841ca0b247" } } ]API format
[ { "pinned": false, "disabled": false, "dataViewId": "90943e30-9a47-11e8-b64d-95841ca0b247", "negate": false, "label": "My nested filter", "group": { "type": "AND", "conditions": [ { "field": "host.keyword", "operator": "is", "value": "www.elastic.co" }, { "type": "OR", "conditions": [ { "field": "index.keyword", "operator": "is", "value": "kibana_sample_data_logs" }, { "type": "OR", "conditions": [ { "field": "extension.keyword", "operator": "is", "value": "css" }, { "field": "extension.keyword", "operator": "is", "value": "gz" } ] } ] } ] } } ]DSL filter
Legacy format
[ { "meta": { "type": "custom", "disabled": false, "negate": false, "alias": null, "key": "query", "index": "90943e30-9a47-11e8-b64d-95841ca0b247" }, "query": { "match": { "agent": { "query": "Mozilla", "fuzziness": "AUTO" } } }, "$state": { "store": "appState" } } ]API format
[ { "pinned": false, "disabled": false, "dataViewId": "90943e30-9a47-11e8-b64d-95841ca0b247", "negate": false, "dsl": { "query": { "match": { "agent": { "query": "Mozilla", "fuzziness": "AUTO" } } } } } ]