Individual Filters for each Metric

Requirement : Objective is to include a script which can be equivalent to SQL function COUNT (CASE WHEN X == ‘1’ THEN 1 ELSE NULL), SUM (CASE WHEN Y == ‘A’ THEN 1 ELSE 0). Precisely known as Conditional Aggregation where each metric can have its own filter
(Example -

While visualizing, the Advanced option which takes JSON format input is really useful which allows us to dynamically manipulate the data unlike scripted fields. But, an extension of the same would be much more beneficial to use.

Working of Advanced JSON script explained:

When we pass a JSON script to Advanced, this gets reflected in the Request made by Kibana. The default template for the Kibana Visualization Request includes the following modules:

  1. “aggs”
  2. “size”
  3. “_source”
  4. “stored_fields”
  5. “script_fields”
  6. “docvalue_fields”
  7. “query”

While checking the Request script on Inspect , the JSON script available under Advanced in the Metric allows to add a custom value for the “aggs”. The below is an example.

Other modules are not bound to this script. It would be very useful to have the possibility of manipulating those modules.

Can anyone confirm the possibility of such computation and if yes, the method to do it. If it is not possible, is it possible to include this in future.

Suggestion: It could be possible if we could replicate the template with all 7 modules for each Metric. The shortcoming could be that it might take away the advantage of fetching all the aggregation results in one request and it is the trade off between customization and performance. May be, there exists a way still to send the customized request at once.

Thanks for your time!

PS: I have checked a few topics related to this where everything concluded that it is not possible. Yet, I am asking this as those were closed for discussion. This is related to my another topic Binding Controls

You can create an enhancement request at

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.