@@ -125,6 +125,7 @@ public function execute(
125125 , string $ typeFrom
126126 , string $ indexTo
127127 , string $ aliasTo
128+ , ?string $ typeTo
128129 , bool $ allowClose
129130 ) : void
130131 {
@@ -143,10 +144,9 @@ public function execute(
143144 $ settings = \reset ($ oldIndexSettings );
144145 $ this ->create ->execute ($ indexTo , [
145146 'settings ' => [
146- 'index ' => $ settings ['settings ' ]['index ' ]['analysis ' ],
147+ 'index ' => $ settings ['settings ' ]['index ' ]['analysis ' ] ?? [] ,
147148 ]
148149 ]);
149- // TODO otestovat
150150
151151 // 2b. Set mapping in new index
152152 $ this ->output ->writeln ('Transferring mapping from index: ' . $ indexFrom . ' and type: ' . $ typeFrom . ' to index: ' . $ indexTo );
@@ -169,17 +169,18 @@ public function execute(
169169 // 4. Input data to new index
170170 // 4a. if closed delete data
171171 // 4b. if open store migrated version
172- /** @var \Spameri\ElasticQuery\Response\Result\Hit $hit */
173- foreach ($ result as $ hit ) {
174- $ this ->processHit ($ indexTo , $ indexFrom , $ hit , $ allowClose );
175-
176- /** @noinspection DisconnectedForeachInstructionInspection */
177- $ progressBar ->advance ();
172+ /** @var \Spameri\ElasticQuery\Response\Result\Hit $response */
173+ foreach ($ result ->hits () as $ response ) {
174+ $ this ->processHit ($ indexTo , $ typeTo , $ indexFrom , $ response , $ allowClose );
178175 }
179- $ from += 5000 ;
180- $ elasticQuery ->options ()->changeFrom ($ from );
181- if ($ result ->stats ()->total () === 0 ) {
176+
177+ if (\count ($ result ->hits ()->getIterator ()) === 0 ) {
182178 $ continue = FALSE ;
179+
180+ } else {
181+ $ progressBar ->advance (5000 );
182+ $ from += 5000 ;
183+ $ elasticQuery ->options ()->changeFrom ($ from );
183184 }
184185 }
185186 $ progressBar ->finish ();
@@ -197,15 +198,15 @@ public function execute(
197198 while ($ canContinue ) {
198199 $ changed = 0 ;
199200 foreach ($ this ->documentMigrateStatus ->storage () as $ documentId => $ documentVersion ) {
200- $ hit = $ this ->get ->execute (
201- new \Spameri \Elastic \Entity \Property \ElasticId ($ documentId ),
201+ $ response = $ this ->get ->execute (
202+ new \Spameri \Elastic \Entity \Property \ElasticId (( string ) $ documentId ),
202203 $ indexFrom ,
203204 $ typeFrom
204205 );
205206
206- if ($ this ->documentMigrateStatus ->isChanged ($ documentId , $ hit ->version ())) {
207+ if ($ this ->documentMigrateStatus ->isChanged (( string ) $ documentId , $ response -> hit () ->version ())) {
207208 // Reindex this document
208- $ this ->processHit ($ indexTo , $ indexFrom , $ hit , $ allowClose );
209+ $ this ->processHit ($ indexTo , $ typeTo , $ indexFrom , $ response , $ allowClose );
209210 $ changed ++;
210211
211212 /** @noinspection DisconnectedForeachInstructionInspection */
@@ -246,6 +247,7 @@ public function execute(
246247 */
247248 public function processHit (
248249 string $ indexTo
250+ , ?string $ typeTo
249251 , string $ indexFrom
250252 , \Spameri \ElasticQuery \Response \Result \Hit $ hit
251253 , bool $ allowClose
@@ -254,7 +256,7 @@ public function processHit(
254256 $ document = new \Spameri \ElasticQuery \Document (
255257 $ indexTo ,
256258 new \Spameri \ElasticQuery \Document \Body \Plain ($ hit ->source ()),
257- $ indexTo ,
259+ $ typeTo ,
258260 $ hit ->id ()
259261 );
260262
0 commit comments