At the moment there are a few ways to programmatically modify an app's search query:
Having all of these competing methods leads to a pretty confusing picture. The visualize refactor made it obvious that we need a simpler API that everyone can use to interact with queries/filters. Now that Kibana supports multiple query languages the need is even more acute. Clients need a way to interact with the query in basic ways without worrying about which language the user happens to have selected.
The new API will likely need to have methods that support legacy filter objects but the primary methods should be language agnostic. The API should not be coupled to UI components, as is the case with the filter_bar currently. The existing QueryManager is a start to this work that needs to be expanded further.
FYI @ppisljar @thomasneirynck @nreese I'm starting to dig into this.
Just putting this here for further reference, after our discussion.
It would be nice it the new API can help satisfy following use-cases:
toString()/toHtml render function. This would allow plugins to render a filter just like it would like in the query-bar. (same colors, same text, same styling, ...). This is useful for plugins that want to "record" earlier states, so you can cycle back/forth more easily between previous states.I'm starting to question whether this is really feasible. It feels like death from a thousand edge cases because kuery and legacy filters can differ in so many ways, and they'll only diverge further over time. Trying to support both is leading to a rather messy API that returns different results and causes different side effects depending on which language is selected. I don't think we can prevent it from becoming a leaky abstraction.
So instead of creating a poor abstraction, I'm starting to think we should just provide an additional API alongside queryFilter for interacting with kuery. Clients can choose to support one or both until we eventually just phase out queryFilter.
The kuery specific API would probably be very simple, it would just provide access to the current query string (if it's not already accessible) and the stateless functions for interacting with the kuery AST.
Most helpful comment
FYI @ppisljar @thomasneirynck @nreese I'm starting to dig into this.