Skip to content

Commit

Permalink
Merge pull request #22 from qporion/master
Browse files Browse the repository at this point in the history
Add rebuild mapping function to change mapping without populate
  • Loading branch information
CheapHasz authored Jan 28, 2022
2 parents 5f2096c + acd1844 commit 76298b1
Showing 1 changed file with 31 additions and 1 deletion.
32 changes: 31 additions & 1 deletion src/Provider/IndexProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,26 @@ class IndexProvider
private $name;
/** @var array */
private $config;
/** @var int */
private $sliceThreadNumber;

public function __construct(
Client $client,
EventDispatcherInterface $eventDispatcher,
string $name,
array $config
array $config,
int $sliceThreadNumber = 4
) {
$this->client = $client;
$this->eventDispatcher = $eventDispatcher;
$this->name = $name;
$this->config = $config;
$this->sliceThreadNumber = $sliceThreadNumber;
}

public function getConfig(): array
{
return $this->config;
}

public function getIndex(): Index
Expand Down Expand Up @@ -65,6 +74,27 @@ public function rebuildIndex($markAsLive = true, $removeOldIndexes = true): Inde
return $index;
}

/**
* Update fields mapping
*/
public function rebuildMapping(): Index
{
$realName = sprintf('%s_rebuild_mapping_%s', $this->name, date('YmdHis'));
$index = $this->getIndexByName($realName);
$index->create($this->config);

$this->client->request('_reindex?slices='.$this->sliceThreadNumber, Request::POST,[
'source' => [
'index' => $this->name,
],
'dest' => [
'index' => $realName,
]
]);

return $this->markAsLive($index, false) ? $index : $this->getIndex();
}

/**
* Remove $this->name alias from each Index
* and set it on $index
Expand Down

0 comments on commit 76298b1

Please sign in to comment.