Write a Scripted field that calculates a rate by dividing the count of 2 text fields

I collect many events from websites and visualize them using Kibana. The events include page loaded", "image clicked". My Kibana index contains an 'event' field that stores these event text values.

I want to show a graph of CTR on the images, so:
total "image clicked" events / total number of all events.

Can I do this using a scripted field?

Many thanks.

1 Like

Hi Jeremy,

I don't think you can do that with a scripted field in Kibana. Scripted fields can only use the numeric values in each individual document and it sounds like you want to use an aggregation of all the documents.

You might get what you are looking for by using the "Percentage" Chart Mode in the Options of your chart.

Also, I think the Timelion plugin for Kibana could probably show the ratio of the values to the aggregate count. Here's some links if you're not familiar with it;


The later the Kibana build you're on, the better the Kibana to Timelion integration is.


Hi Lee,

Thanks for your reply...where do I find "percentage" chart mode eg for a histogram or line chart?

I've asked the creator of TimeLion how to do what I want as well since his video and page don't explain his new querying language.

Not all chart types have Percentage in their Options. A Line chart does not. For the chart types that do have it, you can find it in the options tab.


Or even a pie chart will do - it provides percentages per slice!

Can TimeLion visuals be saved and used in a dashboard like regular visuals?

Many thanks.

Hi Jeremy,

You can use Timelion charts in Kibana 4.5 dashboards. After you install the TimeLion plugin into Kibana you can create a new "Timeseries" visualization (on the Kibana Visualize tab). And you can add that to your Dashboard.

When you're in the TimeLion plugin you can create charts and save sheets, but you cannot put those in a Kibana Dashboard.