22
33# Laravel-OpenSearch
44
5- [ ![ Latest Stable Version] ( http://img.shields.io/github/release/pdphilip/laravel-opensearch.svg )] ( https://packagist.org/packages/pdphilip/laravel-opensearch )
5+ [ ![ Latest Stable Version] ( http://img.shields.io/github/release/pdphilip/laravel-opensearch.svg )] ( https://packagist.org/packages/pdphilip/opensearch )
6+ [ ![ GitHub Tests Action Status] ( https://img.shields.io/github/actions/workflow/status/pdphilip/laravel-opensearch/run-tests.yml?branch=main&label=tests&style=flat-square )] ( https://github.com/pdphilip/laravel-opensearch/actions/workflows/run-tests.yml?query=branch%3Amain )
7+ [ ![ GitHub Code Style Action Status] ( https://img.shields.io/github/actions/workflow/status/pdphilip/laravel-opensearch/phpstan.yml?branch=main&label=code%20style&style=flat-square )] ( https://github.com/pdphilip/laravel-opensearch/actions/workflows/phpstan.yml?query=branch%3Amain++ )
68[ ![ Total Downloads] ( http://img.shields.io/packagist/dm/pdphilip/opensearch.svg )] ( https://packagist.org/packages/pdphilip/opensearch )
79
8-
9- > ** This package has been built off the back of the original [ Elasticsearch version] ( https://github.com/pdphilip/laravel-elasticsearch ) of this package**
10- >
11- > ** The starting point of this package was forked from ` v4.0.1 ` with over 2 years of development**
12-
1310[ OpenSearch] ( https://opensearch.net/ ) is a distributed, community-driven, Apache 2.0-licensed, 100% open-source search and analytics suite used for a broad set of use cases like real-time application monitoring, log analytics, and website
1411search.
1512
1613### An OpenSearch implementation of Laravel's Eloquent ORM
1714
15+ ### The Power of OpenSearch with Laravel's Eloquent
16+
1817This package extends Laravel's Eloquent model and query builder with seamless integration of OpenSearch functionalities. Designed to feel native to Laravel, this package enables you to work with Eloquent models while leveraging the
1918powerful search and analytics capabilities of OpenSearch.
2019
21- Examples :
20+ The Eloquent you already know :
2221
2322``` php
24- $logs = UserLog::where('created_at','>=',Carbon::now()->subDays(30))->get();
23+ UserLog::where('created_at','>=',Carbon::now()->subDays(30))->get();
2524```
2625
2726``` php
28- $updates = UserLog::where('status', 1)->update(['status' => 4]);
27+ UserLog::create([
28+ 'user_id' => '2936adb0-b10d-11ed-8e03-0b234bda3e12',
29+ 'ip' => '62.182.98.146',
30+ 'location' => [40.7185,-74.0025],
31+ 'country_code' => 'US',
32+ 'status' => 1,
33+ ]);
2934```
3035
3136``` php
32- $updates = UserLog::where('status', 1)->paginate(50 );
37+ UserLog::where('status', 1)->update(['status' => 4] );
3338```
3439
3540``` php
36- $profiles = UserProfile::whereIn('country_code',['US','CA'] )->orderByDesc('last_login ')->take(10)->get( );
41+ UserLog::where('status', 4 )->orderByDesc('created_at ')->paginate(50 );
3742```
3843
3944``` php
40- $deleted = UserProfile::where('state','unsubscribed')->where('updated_at','<=',Carbon::now()->subDays(90))->delete();
45+ UserProfile::whereIn('country_code',['US','CA'])
46+ ->orderByDesc('last_login')->take(10)->get();
4147```
4248
4349``` php
44- $search = UserProfile::phrase('loves espressos')->highlight()->search();
50+ UserProfile::where('state','unsubscribed')
51+ ->where('updated_at','<=',Carbon::now()->subDays(90))->delete();
52+ ```
53+
54+ opensearch with Eloquent:
55+
56+ ``` php
57+ UserProfile::searchTerm('Laravel')->orSearchTerm('opensearch')->get();
58+ ```
59+
60+ ``` php
61+ UserProfile::searchPhrasePrefix('loves espressos and t')->highlight()->get();
62+ ```
63+
64+ ``` php
65+ UserProfile::whereMatch('bio', 'PHP')->get();
66+ ```
67+
68+ ``` php
69+ UserLog::whereGeoDistance('location', '10km', [40.7185,-74.0025])->get();
70+ ```
71+
72+ ``` php
73+ UserProfile::whereFuzzy('description', 'qick brwn fx')->get();
74+ ```
75+
76+ Built in Relationships (even to SQL models):
77+
78+ ``` php
79+ UserLog::where('status', 1)->orderByDesc('created_at')->with('user')->get();
4580```
4681
47- ---
48- > ### Read the [ Documentation] ( https://opensearch.pdphilip.com/ )
4982---
5083
84+ # Read the [ Documentation] ( https://opensearch.pdphilip.com/ )
85+
5186## Installation
5287
53- ** Laravel 10 & 11 (main):**
88+ ** Laravel 10.x, 11.x & 12.x (main):**
5489
5590``` bash
5691composer require pdphilip/opensearch
5792```
5893
59- | Laravel Version | Command | Maintained |
60- | -----------------| --------------------------------------------| ------------|
61- | Laravel 10 & 11 | ` composer require pdphilip/opensearch:~2 ` | ✅ |
62- | Laravel 8 & 9 | ` composer require pdphilip/opensearch:~1 ` | ✅ |
94+ | Laravel Version | Command | Maintained |
95+ | --------------------| --------------------------------------------| ------------|
96+ | Laravel 10/11/12 | ` composer require pdphilip/opensearch:~3 ` | ✅ |
97+ | Laravel 10/11 (v2) | ` composer require pdphilip/opensearch:~2 ` | ❌ EOL |
98+ | Laravel 8 & 9 | ` composer require pdphilip/opensearch:~1 ` | ❌ EOL |
6399
64100## Configuration
65101
@@ -69,22 +105,30 @@ composer require pdphilip/opensearch
69105OS_HOSTS =" http://opensearch:9200"
70106OS_USERNAME =
71107OS_PASSWORD =
72- OS_INDEX_PREFIX =my_app
73-
108+ OS_INDEX_PREFIX =my_app_
109+ # prefix will be added to all indexes created by the package with an underscore
110+ # ex: my_app_user_logs for UserLog.php model
111+
112+ # AWS SigV4 Config:
74113OS_SIG_V4_PROVIDER =
75114OS_SIG_V4_REGION =
76115OS_SIG_V4_SERVICE =
77116
117+ # Cert Config:
78118OS_SSL_CERT =
79119OS_SSL_CERT_PASSWORD =
80120OS_SSL_KEY =
81121OS_SSL_KEY_PASSWORD =
82122
123+ # Optional Settings:
83124OS_OPT_VERIFY_SSL =true
84125OS_OPT_RETRIES =
85126OS_OPT_SNIFF_ON_START =
86127OS_OPT_PORT_HOST_HEADERS =
87- OS_ERROR_INDEX =
128+ OS_OPT_ID_SORTABLE =false
129+ OS_OPT_META_HEADERS =true
130+ OS_OPT_BYPASS_MAP_VALIDATION =false
131+ OS_OPT_DEFAULT_LIMIT =1000
88132```
89133
90134For multiple nodes, pass in as comma-separated:
@@ -93,7 +137,7 @@ For multiple nodes, pass in as comma-separated:
93137OS_HOSTS =" http://opensearch-node1:9200,http://opensearch-node2:9200,http://opensearch-node3:9200"
94138```
95139
96- 2 . In ` config/database.php ` , add the opensearch connection:
140+ 2 . In ` config/database.php ` , add the OpensSearch connection:
97141
98142``` php
99143'opensearch' => [
@@ -116,12 +160,15 @@ OS_HOSTS="http://opensearch-node1:9200,http://opensearch-node2:9200,http://opens
116160 ],
117161 'index_prefix' => env('OS_INDEX_PREFIX', false),
118162 'options' => [
119- 'ssl_verification' => env('OS_OPT_VERIFY_SSL', true),
120- 'retires' => env('OS_OPT_RETRIES'),
121- 'sniff_on_start' => env('OS_OPT_SNIFF_ON_START'),
122- 'port_in_host_header' => env('OS_OPT_PORT_HOST_HEADERS'),
163+ 'bypass_map_validation' => env('OS_OPT_BYPASS_MAP_VALIDATION', false),
164+ 'ssl_verification' => env('OS_OPT_VERIFY_SSL', true),
165+ 'retires' => env('OS_OPT_RETRIES',null),
166+ 'sniff_on_start' => env('OS_OPT_SNIFF_ON_START',false),
167+ 'logging' => env('OS_OPT_LOGGING', false),
168+ 'port_in_host_header' => env('OS_OPT_PORT_HOST_HEADERS',false),
169+ 'default_limit' => env('OS_OPT_DEFAULT_LIMIT', 1000),
170+ 'allow_id_sort' => env('OS_OPT_ID_SORTABLE', false),
123171 ],
124- 'error_log_index' => env('OS_ERROR_INDEX', false),
125172],
126173```
127174
@@ -156,34 +203,45 @@ Now, you're all set to use OpenSearch with Laravel as if it were native to the f
156203
157204# Documentation Links
158205
159- ## Getting Started
206+ ### Getting Started
160207
161- - [ Installation] ( https://opensearch.pdphilip.com/#installation )
162- - [ Configuration] ( https://opensearch.pdphilip.com/#configuration )
208+ - [ Installation] ( https://opensearch.pdphilip.com/getting-started )
209+ - [ Configuration] ( https://opensearch.pdphilip.com/getting-started #configuration-guide )
163210
164- ## Eloquent
211+ ### Eloquent
165212
166- - [ The Base Model] ( https://opensearch.pdphilip.com/the-base-model )
167- - [ Querying Models] ( https://opensearch.pdphilip.com/querying-models )
168- - [ Saving Models] ( https://opensearch.pdphilip.com/saving-models )
169- - [ Deleting Models] ( https://opensearch.pdphilip.com/deleting-models )
170- - [ Ordering and Pagination] ( https://opensearch.pdphilip.com/ordering-and-pagination )
171- - [ Distinct and GroupBy] ( https://opensearch.pdphilip.com/distinct )
172- - [ Aggregations] ( https://opensearch.pdphilip.com/aggregation )
173- - [ Chunking] ( https://opensearch.pdphilip.com/chunking )
174- - [ Nested Queries] ( https://opensearch.pdphilip.com/nested-queries )
175- - [ OpenSearch Specific Queries] ( https://opensearch.pdphilip.com/os-specific )
176- - [ Full-Text Search] ( https://opensearch.pdphilip.com/full-text-search )
177- - [ Dynamic Indices] ( https://opensearch.pdphilip.com/dynamic-indices )
213+ - [ The Base Model] ( https://opensearch.pdphilip.com/eloquent/the-base-model )
214+ - [ Saving Models] ( https://opensearch.pdphilip.com/eloquent/saving-models )
215+ - [ Deleting Models] ( https://opensearch.pdphilip.com/eloquent/deleting-models )
216+ - [ Querying Models] ( https://opensearch.pdphilip.com/eloquent/querying-models )
217+ - [ Eloquent Queries] ( https://opensearch.pdphilip.com/eloquent/eloquent-queries )
218+ - [ OS Eloquent Queries] ( https://opensearch.pdphilip.com/eloquent/os-queries )
219+ - [ Cross Fields Search Queries] ( https://opensearch.pdphilip.com/eloquent/search-queries )
220+ - [ Aggregation Queries] ( https://opensearch.pdphilip.com/eloquent/aggregation )
221+ - [ Distinct and GroupBy Queries] ( https://opensearch.pdphilip.com/eloquent/distinct )
222+ - [ Nested Queries] ( https://opensearch.pdphilip.com/eloquent/nested-queries )
223+ - [ Ordering and Pagination] ( https://opensearch.pdphilip.com/eloquent/ordering-and-pagination )
224+ - [ Chunking] ( https://opensearch.pdphilip.com/eloquent/chunking )
225+ - [ Dynamic Indices] ( https://opensearch.pdphilip.com/eloquent/dynamic-indices )
178226
179- ## Relationships
227+ ### Relationships
180228
181- - [ OpenSearch to OpenSearch] ( https://opensearch.pdphilip.com/os-os )
182- - [ OpenSearch to MySQL ] ( https://opensearch.pdphilip.com/os-mysql )
229+ - [ OpenSearch to OpenSearch] ( https://opensearch.pdphilip.com/relationships/ os-os )
230+ - [ OpenSearch to SQL ] ( https://opensearch.pdphilip.com/relationships/ os-sql )
183231
184- ## Schema/Index
232+ ### Migrations: Schema/Index
185233
186- - [ Migrations] ( https://opensearch.pdphilip.com/migrations )
187- - [ Re-indexing Process ] ( https://opensearch.pdphilip.com/re-indexing )
234+ - [ Migrations] ( https://opensearch.pdphilip.com/schema/ migrations )
235+ - [ Index Blueprint ] ( https://opensearch.pdphilip.com/schema/index-blueprint )
188236
189- ---
237+ ### Misc
238+
239+ - [ Mapping OS to Eloquent] ( https://opensearch.pdphilip.com/notes/opensearch-to-eloquent-map )
240+
241+ ## Credits
242+
243+ - [ David Philip] ( https://github.com/pdphilip )
244+
245+ ## License
246+
247+ The MIT License (MIT). Please see [ License File] ( LICENSE.md ) for more information.
0 commit comments