Skip to content

v5.3.0

Choose a tag to compare

@pdphilip pdphilip released this 20 Jan 18:03
· 74 commits to main since this release

This release is compatible with Laravel 10, 11 & 12

New features

Distinct with Relations

distinct() queries now return ElasticCollections;

If a model relation exists and the aggregation is done on the foreign key, you can load the related model

UserLog::where('created_at', '>=', Carbon::now()->subDays(30))
    ->with('user')
    ->orderByDesc('_count')
    ->select('user_id')
    ->distinct(true);

Why: You can now treat distinct aggregations like real Eloquent results, including relationships.

Bulk Distinct Queries

New query method bulkDistinct(array $fields, $includeDocCount = false) - Docs

Run multiple distinct aggregations in parallel within a single Elasticsearch query.

$top3 = UserSession::where('created_at', '>=', Carbon::now()->subDays(30))
    ->limit(3)
    ->bulkDistinct(['country', 'device', 'browser_name'], true);

Why: Massive performance gains vs running sequential distinct queries.

Group By Ranges

groupByRanges() performs a range aggregation on the specified field. - Docs

groupByRanges()->get() — return bucketed results - Docs

groupByRanges()->agg() - apply metric aggregations per bucket -Docs

Group By Date Ranges

groupByDateRanges() performs a date range aggregation on the specified field. - Docs

groupByDateRanges()->get() — bucketed date ranges

groupByDateRanges()->agg() — metrics per date bucket

Model Meta Accessor

New model method getMetaValue($key) - Docs

Convenience method to get a specific meta value from the model instance.

$product = Product::where('color', 'green')->first();
$score = $product->getMetaValue('score');

Bucket Values in Meta

When a bucketed query is executed, the raw bucket data is now stored in model meta. -Docs

$products = Product::distinct('price');
$buckets = $products->map(function ($product) {
    return $product->getMetaValue('bucket');
});

Full Changelog: v5.2.0...v5.3.0