Adding aggregated percentages in data tables or pie charts

What I am trying to do seems simple and doable but for whatever reason i can't find a way to do it:

Use Case:

My data in ES is modeled like so (ignoring metadata):

{
project_name: Test_Group1,
build_name: SomeTests1,
failed_tests: 5,
passed_tests: 10,
total_tests: 15
}

{
project_name: Test_Group1,
build_name: SomeTests2,
failed_tests: 3,
passed_tests: 7,
total_tests: 10
}

What I want to is model this info in a data table visualization like so:

[Project_Name] ------- [ Failed Tests] -------- [Failed Test Percentage]

Test_Group1------------- 8--------------------------- 32%
...

where the Failed Tests column is the sum of all the failed tests across all builds in Test_Group1 project and Failed Test Percentage is the calculated as (sum of all failed tests from all builds in Test_group1 project / sum of total tests from all builds in Test_group1 project)

What I tried doing is creating a scripted field called Failed Test Percentage but this only calculates failure percentage per entry not as an aggregation as wanted in the table above.

Any way to do this?

I would also settle for simply adding a pie chart that shows the percentage of failed tests over total tests for a all builds in a project if this possible.

Hope this is clear,

Thanks

Hi @farooq.muhammad41
I think you can achieve this using TSVB. The only drawback of TSVB is that you need at least one date field (but looking at the data model seems that you can have one associated timestamp).
In TSVB you can create a bucket script aggregation where you can specify 2 aggregations like sum all the total tests and sum all the failed tests. And than you can add a script that compute that percentage.
Just remember two main trick: TSVB works on the last bucket computed depending on the time window and interval configured. This means that if you want to compute this data on a time window of 2 weeks, you also have to specify manually the interval to 2w and uncheck the drop last bucket option.
Here is the example I've done locally to achieve the result you wanted:


the result, adding also another aggregation to sum the total failing test is a table like that one:

For this test I've added a date field with some random dates this year, configured the Time picker with a window that cover those dates and selected a large interval in the panel options:

For the Piechart I think it's not currently possible. The thing is that you want to achieve that using already aggregated data. If you have a set of single document one each test, failed or not, you will be able to build that piechart just specifying the aggregation by terms (test_status) and this will shows the total of failed and succeed tests.

1 Like

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