You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+47Lines changed: 47 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1213,6 +1213,53 @@ Queues
1213
1213
_[Coming]_
1214
1214
1215
1215
1216
+
Dynamic Indies
1217
+
========
1218
+
In some cases you will need to split a model into different indices. There are limits to this to keep within reasonable Laravel ORM bounds, but if you keep the index prefix consistent then the plugin can manage the rest.
1219
+
1220
+
For example, let's imagine we're tracking page hits, the `PageHit.php` model could be
1221
+
1222
+
```php
1223
+
<?php
1224
+
1225
+
namespace App\Models;
1226
+
1227
+
use PDPhilip\Elasticsearch\Eloquent\Model as Eloquent;
1228
+
1229
+
class PageHit extends Eloquent
1230
+
{
1231
+
protected $connection = 'elasticsearch';
1232
+
protected $index = 'page_hits_*'; //Dynamic index
1233
+
1234
+
}
1235
+
```
1236
+
1237
+
If you set a dynamic index you can read/search across all the indices that match the prefix `page_hits_`
1238
+
1239
+
```php
1240
+
$pageHits = PageHit::where('page_id',1)->get();
1241
+
```
1242
+
1243
+
You will need to set the record's actual index when creating a new record, with `setIndex('value')`
1244
+
1245
+
Create example:
1246
+
```php
1247
+
$pageHit = new PageHit
1248
+
$pageHit->page_id = 4;
1249
+
$pageHit->ip = $someIp;
1250
+
$pageHit->setIndex('page_hits_'.date('Y-m-d'));
1251
+
$pageHit->save();
1252
+
1253
+
```
1254
+
1255
+
Each eloquent model will have the current record's index embedded into it, to retrieve it simply call `getRecordIndex()`
0 commit comments