Skip to content

Commit

Permalink
Merge pull request #63 from CheapHasz/init-settings-on-tmp
Browse files Browse the repository at this point in the history
Copy settings from main index when creating the TmpIndex
  • Loading branch information
CheapHasz authored Feb 19, 2019
2 parents 4b874cb + 5b2d504 commit edfc636
Showing 1 changed file with 17 additions and 3 deletions.
20 changes: 17 additions & 3 deletions src/Index.php
Original file line number Diff line number Diff line change
Expand Up @@ -272,11 +272,25 @@ private function createTmpIndex()
$this->client->indices()->delete(['index' => $this->getTmpIndexName()]);
}

// create the tmp index
// retrieve main current settings
$settings = $this->client->indices()->getSettings(['index' => $this->getMainIndexName()]);

$body = [];

if (isset($settings[$this->getMainIndexName()]['settings']['index']['analysis'])) {
// if the settings alreayd existed before, we need to copy them,
// especially if there are custom analyzer, and not only default and default_search,
// As they would not have been transfered, and would break the index creation
$body = ['settings' => ['analysis' => $settings[$this->getMainIndexName()]['settings']['index']['analysis']]];
}

// create the tmp index with main current settings
$this->client->indices()->create([
'index' => $this->getTmpIndexName()
'index' => $this->getTmpIndexName(),
'body' => $body
]);
// retrieve mappings from main index, to copy it to tmp

// retrieve current mappings from main index, to copy it to tmp
$mapping = $this->client->indices()->getMapping(['index' => $this->getMainIndexName()]);
foreach ($mapping[$this->getMainIndexName()]['mappings'] as $type => $mapping) {

Expand Down

0 comments on commit edfc636

Please sign in to comment.