@@ -56,7 +56,12 @@ class IndexManager
56
56
/**
57
57
* @var array
58
58
*/
59
- protected $ indexMapping ;
59
+ protected $ indexMapping = null ;
60
+
61
+ /**
62
+ * @var array
63
+ */
64
+ private $ indexSettings ;
60
65
61
66
/**
62
67
* @var Repository[]
@@ -108,7 +113,7 @@ public function __construct(
108
113
$ this ->finder = $ finder ;
109
114
$ this ->documentConverter = $ documentConverter ;
110
115
$ this ->useAliases = $ indexSettings ['use_aliases ' ];
111
- $ this ->indexMapping = $ this -> getIndexMapping ( $ managerName , $ indexSettings) ;
116
+ $ this ->indexSettings = $ indexSettings ;
112
117
113
118
$ this ->readAlias = $ this ->getBaseIndexName ();
114
119
$ this ->writeAlias = $ this ->getBaseIndexName ();
@@ -134,19 +139,31 @@ public function setEventDispatcher($eventDispatcher)
134
139
$ this ->eventDispatcher = $ eventDispatcher ;
135
140
}
136
141
142
+ /**
143
+ * @return array
144
+ */
145
+ public function getIndexMapping ()
146
+ {
147
+ if (is_null ($ this ->indexMapping )) {
148
+ $ this ->indexMapping = $ this ->buildIndexMapping ($ this ->managerName );
149
+ }
150
+
151
+ return $ this ->indexMapping ;
152
+ }
153
+
137
154
/**
138
155
* Returns mapping array for index
139
156
*
140
- * @param string $indexManagerName
141
- * @param array $indexSettings
157
+ * @param string $indexManagerName
158
+ *
142
159
* @return array
143
160
*/
144
- private function getIndexMapping ($ indexManagerName, array $ indexSettings )
161
+ private function buildIndexMapping ($ indexManagerName )
145
162
{
146
- $ index = ['index ' => $ indexSettings ['name ' ]];
163
+ $ index = ['index ' => $ this -> indexSettings ['name ' ]];
147
164
148
- if (!empty ($ indexSettings ['settings ' ])) {
149
- $ index ['body ' ]['settings ' ] = $ indexSettings ['settings ' ];
165
+ if (!empty ($ this -> indexSettings ['settings ' ])) {
166
+ $ index ['body ' ]['settings ' ] = $ this -> indexSettings ['settings ' ];
150
167
}
151
168
152
169
$ mappings = [];
@@ -245,6 +262,7 @@ public function getRepository($documentClass)
245
262
* Returns the data provider object for a type (provided in short class notation, e.g AppBundle:Product)
246
263
*
247
264
* @param string $documentClass The document class for the type
265
+ *
248
266
* @return ProviderInterface
249
267
*/
250
268
public function getDataProvider ($ documentClass )
@@ -264,11 +282,13 @@ public function getDataProvider($documentClass)
264
282
*/
265
283
private function getBaseIndexName ()
266
284
{
267
- return $ this ->indexMapping [ ' index ' ];
285
+ return $ this ->indexSettings [ ' name ' ];
268
286
}
269
287
270
288
/**
271
289
* Return a name for a new index, which does not already exist
290
+ *
291
+ * @return string
272
292
*/
273
293
private function getUniqueIndexName ()
274
294
{
@@ -288,6 +308,7 @@ private function getUniqueIndexName()
288
308
* Returns the live physical index name, verifying that it exists
289
309
*
290
310
* @return string
311
+ *
291
312
* @throws Exception If live index is not found
292
313
*/
293
314
public function getLiveIndex ()
@@ -321,7 +342,7 @@ public function getLiveIndex()
321
342
*/
322
343
public function createIndex ()
323
344
{
324
- $ settings = $ this ->indexMapping ;
345
+ $ settings = $ this ->getIndexMapping () ;
325
346
326
347
if (true === $ this ->getUseAliases ()) {
327
348
// Make sure the read and write aliases do not exist already as aliases or physical indices
@@ -421,7 +442,7 @@ public function rebuildIndex($deleteOld = false, $cancelExistingRebuild = false)
421
442
}
422
443
423
444
// Create a new index
424
- $ settings = $ this ->indexMapping ;
445
+ $ settings = $ this ->getIndexMapping () ;
425
446
$ oldIndex = $ this ->getLiveIndex ();
426
447
$ newIndex = $ this ->getUniqueIndexName ();
427
448
$ settings ['index ' ] = $ newIndex ;
@@ -532,6 +553,7 @@ public function rebuildIndex($deleteOld = false, $cancelExistingRebuild = false)
532
553
* Makes sure the index exists in Elasticsearch and its aliases (if using such) are properly set up
533
554
*
534
555
* @param bool|true $exceptionIfRebuilding
556
+ *
535
557
* @throws NoReadAliasException When read alias does not exist
536
558
* @throws IndexRebuildingException When the index is rebuilding, according to the current aliases
537
559
* @throws Exception When any other problem with the index or aliases mappings exists
0 commit comments