This release is compatible with Laravel 10, 11 & 12
1. New feature, withTrackTotalHits(bool|int|null $val = true)
Appends the track_total_hits
parameter to the DSL query, setting value to true
will count all the hits embedded in the query meta not capping to Elasticsearch default of 10k hits
$products = Product::limit(5)->withTrackTotalHits(true)->get();
$totalHits = $products->getQueryMeta()->getTotalHits();
This can be set by default for all queries by updating the connection config in database.php
:
'elasticsearch' => [
'driver' => 'elasticsearch',
.....
'options' => [
'track_total_hits' => env('ES_TRACK_TOTAL_HITS', null),
....
],
],
2. New feature, createOrFail(array $attributes)
By default, when using create($attributes)
where $attributes
has an id
that exists, the operation will upsert. createOrFail
will throw a BulkInsertQueryException
with status code 409
if the id
exists
Product::createOrFail([
'id' => 'some-existing-id',
'name' => 'Blender',
'price' => 30,
]);
3. New feature withRefresh(bool|string $refresh)
By default, inserting documents will wait for the shards to refresh, ie: withRefresh(true)
, you can set the refresh flag with the following (as per ES docs):
true
(default)
Refresh the relevant primary and replica shards (not the whole index) immediately after the operation occurs, so that the updated document appears in search results immediately.wait_for
Wait for the changes made by the request to be made visible by a refresh before replying. This doesn’t force an immediate refresh, rather, it waits for a refresh to happen.false
Take no refresh-related actions. The changes made by this request will be made visible at some point after the request returns.
Product::withRefresh('wait_for')->create([
'name' => 'Blender',
'price' => 30,
]);
PRS
- Add withTrackTotalHits method to Builder class to add track_total_hits by @caufab in #76
- feat(query): add op_type=create support and dedupe helpers by @abkrim in #79
Bugfix
- Laravel ^12.23 Compatibility - close #81
New Contributors
Full Changelog: v5.0.7...v5.1.0