Cardinality Aggregation

More info about cardinality aggregation is in the official elasticsearch docs

A single-value metrics aggregation that calculates an approximate count of distinct values.

Simple example

{
     "aggregations" : {
         "author_count" : {
             "cardinality" : {
                 "field" : "author"
             }
         }
     }
 }

And now the query via DSL:

$cardinalityAggregation = new CardinalityAggregation('author_count');
$cardinalityAggregation->setField('author');

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

$queryArray = $search->toArray();