Scripted field in kibana (count)

(Gokul Kathirvel) #1

how can i find the count of the string with some condition in scripted field ???
i know this is wrong i need something concept like this

(Gokul Kathirvel) #2


(Gokul Kathirvel) #3

(doc['gender'].value=="male"){ int count=0; count=count+1; return count; } return false;
am new to kibana,,,t shows error like this
No results match your search criteria

(Jon Budzenski) #4

Scripted fields only have access to the one document at a time, so you can provide a conditional check for certain fields but can't aggregate across documents.

If you want the total count of males you can do a data table visualization with a term or filter aggregation on gender. Does that help?

(Gokul Kathirvel) #5

actually am looking to do percentage between count of male and female...
eg:male 50% and female 50%

(Jon Budzenski) #6

I see. Percentages in the data table aren't supported, but this does work with a pie chart.

If you want it in the data table you can workaround this by creating two scripted field and then using the average metric aggregation.


doc["gender"] == "male" ? 1 : 0


doc["gender"] == "female" ? 1 : 0

Make sure to select the percent field formatter too.

(Robert Foreman) #7

Depending on your situation, you may want to look at a plugin like datasweet, then you can do term query aggregations, and only do math on the client, rather than burden the server with a script for each doc. If that helps

(Gokul Kathirvel) #8

thank you

(system) #9

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