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
@@ -50,6 +50,7 @@ For Example, a base `User` Model will sync with an Elasticsearch `IndexedUser` M
50
50
-[Manage Elasticsearch Migrations](#step-6-define-your-index-models-migrationmap): Define a required blueprint for your index migrations.
51
51
-[Comprehensive CLI Tools](#step-7-monitor-and-administer-all-your-indexes-with-artisan-commands): Manage index health, migrate/rebuild indexes, and more with Artisan commands.
52
52
-[Built-in IndexableBuildState model](#step-8-optionally-access-the-built-in-indexablebuildstate-model-to-track-index-build-states): Track the build states of your indexes.
53
+
-[Built-in Migration Logs](#step-9-optionally-access-the-built-in-indexablemigrationlog-model-for-index-migration-status): Track the build states of your indexes.
53
54
54
55
# Requirements
55
56
@@ -70,13 +71,15 @@ Publish config file and run the migrations with:
70
71
php artisan lens:install
71
72
```
72
73
73
-
# Usage (Walkthrough)
74
+
# Usage
75
+
76
+
The Walkthrough Steps below will show all the features by way of eaxmple
74
77
75
78
## Step 1: Zero config setup
76
79
77
80
1. Add the Indexable Trait to Your Base Model:
78
81
79
-
Include the `Indexable` trait in your base model to enable automatic indexing.
82
+
-Include the `Indexable` trait in your base model to enable automatic indexing.
80
83
81
84
```php
82
85
use PDPhilip\ElasticLens\Indexable;
@@ -88,21 +91,21 @@ class User extends Eloquent implements Authenticatable, CanResetPassword
88
91
89
92
2. Create an Index Model for Your Base Model:
90
93
91
-
Define a corresponding Index Model that extends `IndexModel`. This model will sync and manage the Elasticsearch index for your `Base Model`.
92
-
93
-
By default, ElasticLens expects the `Index Model` to be named as `Indexed` + `BaseModelName` and located in the `App\Models\Indexes` directory. For example:
94
-
95
-
`App\Models\Indexes\IndexedUser.php`
94
+
- Define a corresponding Index Model that extends `IndexModel`. This model will sync and manage the Elasticsearch index for your `Base Model`.
95
+
- By default, ElasticLens expects the `Index Model` to be named as `Indexed` + `BaseModelName` and located in the `App\Models\Indexes` directory.
96
+
- For example: `App\Models\Indexes\IndexedUser.php`
96
97
97
98
```php
98
99
namespace App\Models\Indexes;
99
100
100
101
use PDPhilip\ElasticLens\IndexModel;
101
102
102
103
class IndexedUser extends IndexModel{}
104
+
103
105
```
104
106
105
-
That's it! Your User model will now automatically sync with the IndexedUser model whenever changes occur. You can search your User model effortlessly, like:
107
+
- That's it! Your User model will now automatically sync with the IndexedUser model whenever changes occur. You can search your User model effortlessly, like:
Since the `viaIndex()` taps into the `IndexModel`, the results returned will be instances of `IndexedUser`, not the base `User` model. This can be useful for display purposes, such as highlighting embedded fields.
232
+
- Since the `viaIndex()` taps into the `IndexModel`, the results returned will be instances of `IndexedUser`, not the base `User` model.
233
+
- This can be useful for display purposes, such as highlighting embedded fields.
234
+
-**<u>However, in most cases you'll need to return and work with the `Base Model`</u>**
230
235
231
-
### However, in most cases you'll need to return and work with the `Base Model`
236
+
### To search and return results as `Base Models` use `asModel()`
232
237
233
-
To get the results as base models simply chain `->asModel()` at the end of your query:
238
+
- Simply chain `->asModel()` at the end of your query:
**Note**: While you can query the `IndexableBuildState` model directly, avoid writing or deleting records within it manually, as this can interfere with the health checks and overall integrity of the indexing process. The model should be
730
-
used for reading purposes only to ensure accurate monitoring and reporting.
747
+
**Note**: While you can query the `IndexableBuildState` model directly, avoid writing or deleting records within it manually, as this can interfere with the health checks and overall integrity of the indexing process. The model should be used for reading purposes only to ensure accurate monitoring and reporting.
748
+
749
+
---
750
+
751
+
## Step 9: Optionally Access the Built-in `IndexableMigrationLog` Model for Index Migration Status
752
+
753
+
ElasticLens includes a built-in `IndexableMigrationLog` model for monitoring and tracking the state of index migrations. This model logs each migration related to an `Index Model`.
754
+
755
+
### Model Fields:
756
+
757
+
- string `$index_model`: The migrated Index Model.
758
+
- IndexableMigrationLogState `$state`: State of the migration
759
+
- array `$map`: Migration map that was passed to Elasticsearch.
760
+
- int `$version_major`: Major version of the indexing process.
761
+
- int `$version_minor`: Minor version of the indexing process.
762
+
- Carbon `$created_at`: Timestamp of when the migration was created.
763
+
764
+
### Attributes:
765
+
766
+
-@property-read string `$version`: Parsed version ex v2.03
767
+
-@property-read string `$state_name`: Current state name.
768
+
-@property-read string `$state_color`: Color representing the current state.
**Note**: While you can query the `IndexableMigrationLog` model directly, avoid writing or deleting records within it manually, as this can interfere with versioing of the migrations. The model should be used for reading purposes only to ensure accuracy.
0 commit comments