Scripted field in kibana (count)

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?