You can user terms aggregation to get distinct values from your _source.
In your case
GET persons/_search
{
"size":"0",
"aggs" : {
"uniq_gender" : {
"terms" : { "field" : "Gender" }
}
}
}
As you have mentioned you don't want any other data from _source hence you can give size=0.
This will give you all unique Gender values with their count in the response.
(field data should be enabled for your field, in case it isn't then you can user multi field to create a sub field and use that one.)
Apache, Apache Lucene, Apache Hadoop, Hadoop, HDFS and the yellow elephant
logo are trademarks of the
Apache Software Foundation
in the United States and/or other countries.