Scripted field in kibana (count)

how can i find the count of the string with some condition in scripted field ???
eg:doc['gender'].count.value=="male"
i know this is wrong i need something concept like this

anybody??

(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

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?

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

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.

percent_male

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

percent_female

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

Make sure to select the percent field formatter too.

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

thank you

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