I have the following type on ElasticSearch:
{ bundle_id: 11141 bundle_name: bla_bla country: India }
I want to perform the following query (I'll describe it in SQL):
SELECT COUNT(DISTINCT bundle_id) FROM my_type WHERE county IN ('india', 'usa')
If a search request results in more than ten hits, ElasticSearch will, by default, only return the first ten hits. To override that default value in order to retrieve more or fewer hits, we can add a size parameter to the search request body.
You can user terms aggregation to get distinct values from your _source. 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.
Elasticsearch Aggregations provide you with the ability to group and perform calculations and statistics (such as sums and averages) on your data by using a simple search query. An aggregation can be viewed as a working unit that builds analytical information across a set of documents.
Have a look at Terms Aggregation. This is what you are looking for.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With