Releases: pdphilip/laravel-elasticsearch
v5.2.0
This release is compatible with Laravel 10, 11 & 12
New Feature: Query String Queries
This release introduces Query String Queries, bringing full Elasticsearch query_string syntax support directly into your Eloquent-style queries.
- Method:
searchQueryString(query, $fields = null, $options = [])and related methods (orSearchQueryString,searchNotQueryString, etc.) - Supports all
query_stringfeatures — logical operators, wildcards, fuzziness, ranges, regex, boosting, field scoping, and more - Includes a dedicated
QueryStringOptionsclass for fluent option configuration or array-based parameters - See Tests
- Full documentation
Example:
Product::searchQueryString('status:(active OR pending) name:(full text search)^2')->get();
Product::searchQueryString('price:[5 TO 19}')->get();
// vanilla optional, +pizza required, -ice forbidden
Product::searchQueryString('vanilla +pizza -ice', function (QueryStringOptions $options) {
$options->type('cross_fields')->fuzziness(2);
})->get();
//etcOrdering enhancement: unmapped_type
- You can now add an
unmapped_typeflag to your ordering query #88
Product::query()->orderBy('name', 'desc', ['unmapped_type' => 'keyword'])->get();Bugfix
- Fixed issue where limit values were being reset on bucket aggregations #84
Full Changelog: v5.1.0...v5.2.0
v5.1.0
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
v5.0.7
v5.0.6
v5.0.5
v5.0.4
This release is compatible with Laravel 10, 11 & 12
What's changed
- Connection
disconnect()resets connection - removing connection is unnecessary in the context of Elasticsearch. Issue #64 - Added
getTotalHits()helper method from query meta - Bug fix:
searchFuzzy()parses options as a closure - Minor code reorganising
Full Changelog: v5.0.3...v5.0.4
v5.0.3
This release is compatible with Laravel 10, 11 & 12
What's changed
- Bug fix: Internal model attribute
metarenamed to_metato avoid the issue where a model could have a field calledmeta - Bug fix:
highlight()passed without fields did not highlight all hits - Bug fix: Hybrid
BelongsToin some SQL cases used ES connection - Bug fix:
orderBy('_score')was not parsing correctly - Bug fix: Edge case where a string value was being seen as callable
Full Changelog: v5.0.2...v5.0.3
v5.0.2
This release is compatible with Laravel 10, 11 & 12
What's changed
1. New feature, bulkInsert()
bulkInsert() is identical to insert() but will continue on errors and return an array of the results.
People::bulkInsert([
[
'id' => '_edo3ZUBnJmuNNwymfhJ', // Will update (if id exists)
'name' => 'Jane Doe',
'status' => 1,
],
[
'name' => 'John Doe', // Will Create
'status' => 2,
],
[
'name' => 'John Dope',
'status' => 3,
'created_at' => 'xxxxxx', // Will fail
],
]);Returns:
{
"hasErrors": true,
"total": 3,
"took": 0,
"success": 2,
"created": 1,
"modified": 1,
"failed": 1,
"errors": [
{
"id": "Y-dp3ZUBnJmuNNwy7vkF",
"type": "document_parsing_exception",
"reason": "[1:45] failed to parse field [created_at] of type [date] in document with id 'Y-dp3ZUBnJmuNNwy7vkF'. Preview of field's value: 'xxxxxx'"
}
]
}2. Bug fix: distinct() aggregation now appends searchAfter key in meta
Full Changelog: v5.0.1...v5.0.2
v5.0.1
This release is compatible with Laravel 10, 11 & 12
What's changed
- Updated model docs for comprehensive IDE support when building queries
- Added
orderByNestedDesc() - Removed & replaced compatibility-loader that depended on
class_aliasto set the correct traits for the given Laravel version
Full Changelog: v5.0.0...v5.0.1
v5.0.0
We’re excited to announce v5 of the laravel-elasticsearch package - compatible with Laravel 10, 11, and 12.
Acknowledgement
V5 is the brainchild of @use-the-fork and is a near-complete rewrite of the package; packed with powerful new features, deep integration with Elasticsearch’s full capabilities, and a much tighter alignment with Laravel’s Eloquent. It lays a solid, future-proof foundation for everything that comes next.
Upgrading
-
Please take a look at the upgrade guide carefully, as there are several significant breaking changes.
"pdphilip/elasticsearch": "^5",Breaking Changes
1. Connection
- Index Prefix Handling
TheES_INDEX_PREFIXno longer auto-appends an underscore (_).
Old behavior:ES_INDEX_PREFIX=my_prefix→my_prefix_
New: set explicitly if needed →ES_INDEX_PREFIX=my_prefix_
2. Models
-
Model ID Field
$model->_idis deprecated. Use$model->idinstead.
If your model had a separateidfield, you must rename it. -
Default Limit Constant
MAX_SIZEconstant is removed. Use$defaultLimitproperty:use PDPhilip\Elasticsearch\Eloquent\Model; class Product extends Model { protected $defaultLimit = 10000; protected $connection = 'elasticsearch'; }
3. Queries
-
where()Behavior ChangedNow uses term query instead of match.
// Old: Product::where('name', 'John')->get(); // match query // New: Product::whereMatch('name', 'John')->get(); // match query Product::where('name', 'John')->get(); // term query
-
orderByRandom()RemovedReplace with
functionScore()Docs -
Full-text Search Options Updated
Methods likeasFuzzy(),setMinShouldMatch(),setBoost()removed.
Use callback-based SearchOptions instead:Product::searchTerm('espresso time', function (SearchOptions $options) { $options->searchFuzzy(); $options->boost(2); $options->minimumShouldMatch(2); })->get();
-
Legacy Search Methods Removed
All{xx}->search()methods been removed. Use{multi_match}->get()instead.
4. Distinct & GroupBy
-
distinct()andgroupBy()behavior updated. DocsReview queries using them and refactor accordingly.
5. Schema
-
IndexBlueprintandAnalyzerBlueprinthas been removed and replaced with a singleBlueprintclass- use PDPhilip\Elasticsearch\Schema\IndexBlueprint; - use PDPhilip\Elasticsearch\Schema\AnalyzerBlueprint; use PDPhilip\Elasticsearch\Schema\Blueprint;
-
Schema::hasIndexhas been removed. UseSchema::hasTableorSchema::indexExistsinstead. -
geo($field)field property has been replaced withgeoPoint($field) -
{field}->index($bool)field property has been replaced with{field}->indexField($bool); -
alias()field type has been removed. UsealiasField()instead. -
settings()method has been replaced withwithSetting() -
map()method has been replaced withwithMapping() -
analyzer()method has been replaced withaddAnalyzer() -
tokenizer()method has been replaced withaddTokenizer() -
charFilter()method has been replaced withaddCharFilter() -
filter()method has been replaced withaddFilter()
6. Dynamic Indices
- Dynamic indices are now managed by the
DynamicIndextrait. upgrade guide
New features
1. Laravel-Generated IDs
- You can now generate Elasticsearch ids in Laravel Docs
2. Fluent query options as a callback
- All clauses in the query builder now accept an optional callback of Elasticsearch options to be applied to the clause. Docs
3. Belongs to Many Relationships
- Belongs to many relationships are now supported. Docs
4. New queries
5. New aggregations
- Boxplot Aggregations Docs
- Stats Aggregations Docs
- Extended Stats Aggregations - Docs
- Cardinality Aggregations - Docs
- Median Absolute Deviation Aggregations - Docs
- Percentiles Aggregations - Docs
- String Stats Aggregations - Docs
6. Migratons: Add Normalizer
- Normalizers can now be defined in migrations. Docs
7. Direct Access to Elasticsearch PHP client
Connection::on('elasticsearch')->elastic()->{clientMethod}();What's Changed
Full Changelog: v4.5.3...v5.0.0