2
2
3
3
# Laravel-OpenSearch
4
4
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++ )
6
8
[ ![ Total Downloads] ( http://img.shields.io/packagist/dm/pdphilip/opensearch.svg )] ( https://packagist.org/packages/pdphilip/opensearch )
7
9
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
-
13
10
[ 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
14
11
search.
15
12
16
13
### An OpenSearch implementation of Laravel's Eloquent ORM
17
14
15
+ ### The Power of OpenSearch with Laravel's Eloquent
16
+
18
17
This 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
19
18
powerful search and analytics capabilities of OpenSearch.
20
19
21
- Examples :
20
+ The Eloquent you already know :
22
21
23
22
``` php
24
- $logs = UserLog::where('created_at','>=',Carbon::now()->subDays(30))->get();
23
+ UserLog::where('created_at','>=',Carbon::now()->subDays(30))->get();
25
24
```
26
25
27
26
``` 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
+ ]);
29
34
```
30
35
31
36
``` php
32
- $updates = UserLog::where('status', 1)->paginate(50 );
37
+ UserLog::where('status', 1)->update(['status' => 4] );
33
38
```
34
39
35
40
``` 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 );
37
42
```
38
43
39
44
``` 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();
41
47
```
42
48
43
49
``` 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();
45
80
```
46
81
47
- ---
48
- > ### Read the [ Documentation] ( https://opensearch.pdphilip.com/ )
49
82
---
50
83
84
+ # Read the [ Documentation] ( https://opensearch.pdphilip.com/ )
85
+
51
86
## Installation
52
87
53
- ** Laravel 10 & 11 (main):**
88
+ ** Laravel 10.x, 11.x & 12.x (main):**
54
89
55
90
``` bash
56
91
composer require pdphilip/opensearch
57
92
```
58
93
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 |
63
99
64
100
## Configuration
65
101
@@ -69,22 +105,30 @@ composer require pdphilip/opensearch
69
105
OS_HOSTS =" http://opensearch:9200"
70
106
OS_USERNAME =
71
107
OS_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:
74
113
OS_SIG_V4_PROVIDER =
75
114
OS_SIG_V4_REGION =
76
115
OS_SIG_V4_SERVICE =
77
116
117
+ # Cert Config:
78
118
OS_SSL_CERT =
79
119
OS_SSL_CERT_PASSWORD =
80
120
OS_SSL_KEY =
81
121
OS_SSL_KEY_PASSWORD =
82
122
123
+ # Optional Settings:
83
124
OS_OPT_VERIFY_SSL =true
84
125
OS_OPT_RETRIES =
85
126
OS_OPT_SNIFF_ON_START =
86
127
OS_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
88
132
```
89
133
90
134
For multiple nodes, pass in as comma-separated:
@@ -93,7 +137,7 @@ For multiple nodes, pass in as comma-separated:
93
137
OS_HOSTS =" http://opensearch-node1:9200,http://opensearch-node2:9200,http://opensearch-node3:9200"
94
138
```
95
139
96
- 2 . In ` config/database.php ` , add the opensearch connection:
140
+ 2 . In ` config/database.php ` , add the OpensSearch connection:
97
141
98
142
``` php
99
143
'opensearch' => [
@@ -116,12 +160,15 @@ OS_HOSTS="http://opensearch-node1:9200,http://opensearch-node2:9200,http://opens
116
160
],
117
161
'index_prefix' => env('OS_INDEX_PREFIX', false),
118
162
'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),
123
171
],
124
- 'error_log_index' => env('OS_ERROR_INDEX', false),
125
172
],
126
173
```
127
174
@@ -156,34 +203,45 @@ Now, you're all set to use OpenSearch with Laravel as if it were native to the f
156
203
157
204
# Documentation Links
158
205
159
- ## Getting Started
206
+ ### Getting Started
160
207
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 )
163
210
164
- ## Eloquent
211
+ ### Eloquent
165
212
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 )
178
226
179
- ## Relationships
227
+ ### Relationships
180
228
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 )
183
231
184
- ## Schema/Index
232
+ ### Migrations: Schema/Index
185
233
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 )
188
236
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