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