Skip to content

Version 2.6.0

Compare
Choose a tag to compare
@Radiergummi Radiergummi released this 16 Sep 10:00
· 22 commits to 2.x since this release
de3e616

Changelog

  • Feature: Added aggregate() method to query builder, allowing to fluently add aggregations.
  • Chore: Updated dependencies

Adding aggregations

From 2.6.0 onwards, you can add aggregations to your query using the fluent query builder:

$query->aggregate('color');

Specifying the name only will create a simple term query:

{
    "aggs": {
        "color": {
            "terms": {
                "field": "color"
            }
    }
}

Pass a string to use a different field:

$query->aggregate('color', 'color_field');

Specifying the name only will create a simple term query:

{
    "aggs": {
        "color": {
            "terms": {
                "field": "color_field"
            }
    }
}

To have custom aggregations, pass an array instead of the field name:

$query->aggregate('date', [
    'date_histogram' => [
        'field' => 'date',
        'interval' => 'month'
    ]
]);

Specifying the name only will create a simple term query:

{
    "aggs": {
        "date": {
            "date_histogram": {
                "field": "date",
                "interval": "month"
            }
        }
    }
}