Elastica

A PHP client for elasticsearch.

Fork me on GitHub

Aggregations

Elasticsearch provides a way to aggregate data which is mapped by accordingly classes that can be added to the query.

Adding aggregations to query

New aggregations can be created and added to the query afterwards:

1
2
3
4
5
6
$facet = new \Elastica\Aggregation\Terms('Some label', 'fieldName');
$facet->setField('fieldName');
$query->addAggregation($facet);

$facet = new \Elastica\Aggregation\DateHistogram('Some label again', 'fieldName', 'month');
$query->addAggregation($facet);

For further information check out the different classes and official Documentation.

Accessing Aggregations in result

Returned aggregations are available at $searchResult->getAggregations();.