Terms Aggregation

More info about terms aggregation is in the official elasticsearch docs

A multi-bucket value source based aggregation where buckets are dynamically built - one per unique value.

Simple example

{
    "aggregations" : {
        "genders" : {
            "terms" : { "field" : "gender" }
        }
    }
}

And now the query via DSL:

$termsAggregation = new TermsAggregation('genders', 'gender');

$search = new Search();
$search->addAggregation($termsAggregation);

$queryArray = $search->toArray();