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
@@ -92,14 +92,33 @@ Elasticsearch query logs will go. Query logging is done at a 'debug' level.
92
92
## Getting a Index object
93
93
94
94
Index objects are the equivalent of `ORM\Table` instances in elastic search. You can
95
-
use the `IndexRegistry` factory to get instances, much like `TableRegistry`:
95
+
use the `IndexLocatorAwareTrait`to get instances in your classes:
96
96
97
97
```php
98
-
use Cake\ElasticSearch\IndexRegistry;
98
+
use Cake\ElasticSearch\Datasource\IndexLocatorAwareTrait;
99
99
100
-
$comments = IndexRegistry::get('Comments');
100
+
class MyClass
101
+
{
102
+
use IndexLocatorAwareTrait;
103
+
104
+
public function someMethod()
105
+
{
106
+
$comments = $this->fetchIndex('Comments');
107
+
}
108
+
}
101
109
```
102
110
111
+
Alternatively, you can use the `IndexLocator` directly:
112
+
113
+
```php
114
+
use Cake\ElasticSearch\Datasource\IndexLocator;
115
+
116
+
$locator = new IndexLocator();
117
+
$comments = $locator->get('Comments');
118
+
```
119
+
120
+
> **Note for upgrading users**: The `IndexRegistry` class has been deprecated since version 3.4.3. If you're upgrading from an older version, replace `IndexRegistry::get('Comments')` with the `IndexLocatorAwareTrait` approach shown above or use `IndexLocator` directly.
121
+
103
122
If you have loaded the plugin with bootstrap enabled you could load indexes using the model factory in your controllers
104
123
```php
105
124
class SomeController extends AppController
@@ -119,7 +138,7 @@ class SomeController extends AppController
119
138
120
139
Each `Index` object needs a correspondent Elasticsearch _index_, just like most of `ORM\Table` needs a database _table_.
121
140
122
-
In the above example, if you have defined a class as `CommentsIndex` and the `IndexRegistry` can find it, the `$comments` will receive a initialized object with inner configurations of connection and index. But if you don't have that class, a default one will be initialized and the index name on Elasticsearch mapped to the class.
141
+
In the above example, if you have defined a class as `CommentsIndex` and the `IndexLocator` can find it, the `$comments` will receive an initialized object with inner configurations of connection and index. But if you don't have that class, a default one will be initialized and the index name on Elasticsearch mapped to the class.
0 commit comments