Releases: pdphilip/laravel-opensearch
v3.0.1
This release is compatible with Laravel 10, 11 & 12
What's Changed
Bug fix: Chunking $count value fixed for setting query limit correctly, via pdphilip/laravel-elasticsearch#68
Full Changelog: v3.0.0...v3.0.1
v3.0.0
We’re excited to announce v3 of the laravel-opensearch package - compatible with Laravel 10, 11, and 12.
Intro
V3 is a near-complete rewrite of the package; packed with powerful new features, deep integration with OpensSearch'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/opensearch": "^3",
Breaking Changes
1. Connection
- Index Prefix Handling
TheOS_INDEX_PREFIX
no longer auto-appends an underscore (_
).
Old behavior:OS_INDEX_PREFIX=my_prefix
→my_prefix_
New: set explicitly if needed →OS_INDEX_PREFIX=my_prefix_
2. Models
-
Model ID Field
$model->_id
is deprecated. Use$model->id
instead.
If your model had a separateid
field, you must rename it. -
Default Limit Constant
MAX_SIZE
constant is removed. Use$defaultLimit
property:use PDPhilip\OpensSearch\Eloquent\Model; class Product extends Model { protected $defaultLimit = 10000; protected $connection = 'opensearch'; }
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
-
IndexBlueprint
andAnalyzerBlueprint
has been removed and replaced with a singleBlueprint
class- use PDPhilip\OpensSearch\Schema\IndexBlueprint; - use PDPhilip\OpensSearch\Schema\AnalyzerBlueprint; use PDPhilip\OpensSearch\Schema\Blueprint;
-
Schema::hasIndex
has been removed. UseSchema::hasTable
orSchema::indexExists
instead. -
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
DynamicIndex
trait. upgrade guide
New features
1. Laravel-Generated IDs
- You can now generate OpensSearch ids in Laravel Docs
2. Fluent query options as a callback
- All clauses in the query builder now accept an optional callback of OpensSearch 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
- Stats Aggregations Docs
- Extended Stats Aggregations - Docs
- Cardinality Aggregations - Docs
- Median Absolute Deviation Aggregations - Docs
- Percentiles Aggregations - Docs
6. Migrations: Add Normalizer
- Normalizers can now be defined in migrations. Docs
7. Direct Access to OpensSearch PHP client
Connection::on('opensearch')-> openClient()->{clientMethod}();
Full Changelog: v2.0.6...v3.0.0
v2.0.6
What's Changed
- Fix when first insert value is array by @guram-vashakidze in #15
Full Changelog: v2.0.5...v2.0.6
v2.0.5
What's Changed
- Add ability to use search_after parameter by @guram-vashakidze in #14
New Contributors
- @guram-vashakidze made their first contribution in #14
Full Changelog: v2.0.4...v2.0.5
v2.0.4
What's Changed
- query operator as lowercase to escape case-sensitive troubles. by @sergoslav in #9
New Contributors
- @sergoslav made their first contribution in #9
Full Changelog: v2.0.3...v2.0.4
v2.0.3
This unified release includes updates for multiple Laravel versions:
Upgrades
sum()
,avg()
,min()
andmax()
can now process multiple fields in one call
Product::where('color','blue')->avg(['orders', 'price']);
//Previously required two separate calls:
Product::where('color','blue')->avg('orders');
Product::where('color','blue')->avg('price');
rawSearch(array $bodyParams, bool $returnRaw = false)
- a second bool parameter will return data as is (unsanitized) if set to
true
Product::rawSearch($body, true);
Bug fixes
- rawAggregation with multiple aggregations now returns all aggs
- Fixed issue when saving fields where the data didn't change threw an error
Full Changelog: v2.0.2...v2.0.3
v2.0.2 - (Unified with v1.0.2)
This unified release includes updates for multiple Laravel versions:
New Features
wherePhrasePrefix($field, $phraseWithPrefix)
Method for looking up a specific sequence of words where the last word starts with a particular prefix
Person::wherePhrasePrefix('description', 'loves es')->get();
// returns: loves espresso, loves essays, loves eskimos, etc
Docs: https://opensearch.pdphilip.com/os-specific#where-phrase-prefix
phrase($field)
Method for searching across multiple fields for a specific phrase (sequence of words in order)
Book::phrase('United States')->orPhrase('United Kingdom')->search();
// Search for books that contain either 'United States' or 'United Kingdom', phrases like 'United Emirates' will not be included.
Docs: https://opensearch.pdphilip.com/full-text-search#phrase-search-phrase
agg(array $functions,$field)
Optimization method that allows you to call multiple aggregation functions on a single field in one call. Issue #3
Available aggregation functions: count
, avg
, min
, max
, sum
, matrix
.
Product::where('is_active',true)->agg(['count','avg','min','max','sum'],'sales');
Docs: https://opensearch.pdphilip.com/aggregation#grouped-aggregations
toDsl()
(or toSql()
)
Returns the parsed DSL query from the query builder. Issue #2
Product::whereIn('color', ['red', 'green'])->orderByDesc('sales')->toDsl();
Returns
{
"index": "products",
"body": {
"query": {
"terms": {
"color.keyword": [
"red",
"green"
]
}
},
"_source": [
"*"
],
"sort": [
{
"sales": {
"order": "desc"
}
}
]
}
}
Docs: https://opensearch.pdphilip.com/os-specific#to-dsl
Bug fixes
- Fixed issue where meta data was being written to indexes in some cases
Upgrades
- Fixed error tracking index for writing OS errors to a dedicated index - Issue #4
// database.php
'opensearch' => [
'driver' => 'opensearch',
//......
//......
//......
'error_log_index' => env('OS_ERROR_INDEX', false),
],
- White space code clean-up
'opensearch' => [
'driver' => 'opensearch',
'hosts' => explode(',', env('OS_HOSTS', 'http://localhost:9200')),
'basic_auth' => [
'username' => env('OS_USERNAME', ''),
'password' => env('OS_PASSWORD', ''),
],
'sig_v4' => [
'provider' => env('OS_SIG_V4_PROVIDER'),
'region' => env('OS_SIG_V4_REGION'),
'service' => env('OS_SIG_V4_SERVICE'),
],
'ssl' => [
'cert' => env('OS_SSL_CERT', ''),
'cert_password' => env('OS_SSL_CERT_PASSWORD', ''),
'key' => env('OS_SSL_KEY', ''),
'key_password' => env('OS_SSL_KEY_PASSWORD', ''),
],
'index_prefix' => env('OS_INDEX_PREFIX', false),
'options' => [
'ssl_verification' => env('OS_OPT_VERIFY_SSL', true),
'retires' => env('OS_OPT_RETRIES'),
'sniff_on_start' => env('OS_OPT_SNIFF_ON_START'),
'port_in_host_header' => env('OS_OPT_PORT_HOST_HEADERS'),
],
'error_log_index' => env('OS_ERROR_INDEX', false),
],
'opensearch_cloud' => [
'driver' => 'opensearch',
'hosts' => explode(',', env('OS_CLOUD_HOSTS', 'http://localhost:9200')),
'basic_auth' => [
'username' => env('OS_CLOUD_USERNAME', ''),
'password' => env('OS_CLOUD_PASSWORD', ''),
],
'sig_v4' => [
'provider' => env('OS_CLOUD_SIG_V4_PROVIDER'),
'region' => env('OS_CLOUD_SIG_V4_REGION'),
'service' => env('OS_CLOUD_SIG_V4_SERVICE'),
],
'ssl' => [
'cert' => env('OS_CLOUD_SSL_CERT', ''),
'cert_password' => env('OS_CLOUD_SSL_CERT_PASSWORD', ''),
'key' => env('OS_CLOUD_SSL_KEY', ''),
'key_password' => env('OS_CLOUD_SSL_KEY_PASSWORD', ''),
],
'index_prefix' => env('OS_CLOUD_INDEX_PREFIX', false),
'options' => [
'ssl_verification' => env('OS_CLOUD_OPT_VERIFY_SSL', true),
'retires' => env('OS_CLOUD_OPT_RETRIES'),
'sniff_on_start' => env('OS_CLOUD_OPT_SNIFF_ON_START'),
'port_in_host_header' => env('OS_CLOUD_OPT_PORT_HOST_HEADERS'),
],
'error_log_index' => env('OS_CLOUD_ERROR_INDEX', false),
],
v2.0.1
New Features
New numeric type mappings for IndexBlueprint
double($field)
- A double-precision 64-bit IEEE 754 floating point number, restricted to finite values.byte($field)
- A signed 8-bit integer with a minimum value of -128 and a maximum value of 127.halfFloat($field)
- A half-precision 16-bit IEEE 754 floating point number, restricted to finite values.scaledFloat($field, $scalingFactor = 100)
- A floating point number that is backed by a long, scaled by a fixed double scaling factor.unsignedLong($field)
- An unsigned 64-bit integer with a minimum value of 0 and a maximum value of 264-1.
Example:
Schema::create('my_index', function (IndexBlueprint $index) {
$index->double('some_field_a');
$index->byte('some_field_b');
$index->halfFloat('some_field_c');
$index->scaledFloat('some_field_d', 100);
$index->unsignedLong('some_field_e');
});
Bug fixes
- Fixed Connection to process options
Full Changelog: v2.0.0...v2.0.1
v1.0.1
New Features
New numeric type mappings for IndexBlueprint
double($field)
- A double-precision 64-bit IEEE 754 floating point number, restricted to finite values.byte($field)
- A signed 8-bit integer with a minimum value of -128 and a maximum value of 127.halfFloat($field)
- A half-precision 16-bit IEEE 754 floating point number, restricted to finite values.scaledFloat($field, $scalingFactor = 100)
- A floating point number that is backed by a long, scaled by a fixed double scaling factor.unsignedLong($field)
- An unsigned 64-bit integer with a minimum value of 0 and a maximum value of 264-1.
Example:
Schema::create('my_index', function (IndexBlueprint $index) {
$index->double('some_field_a');
$index->byte('some_field_b');
$index->halfFloat('some_field_c');
$index->scaledFloat('some_field_d', 100);
$index->unsignedLong('some_field_e');
});
Bug fixes
- Fixed Connection to process options
Full Changelog: v1.0.0...v1.0.1
v2.0.0
Initial Release for Laravel 10 & 11
composer require pdphilip/elasticsearch:~2
Documentation: https://opensearch.pdphilip.com/
Note: This package has been built off the back of the original Elasticsearch version of this package