I am creating search application. When I reindex data into elasticsearch there should not be downtime while reindexing. I want to make reindexing process with zero downtime.I'm trying to do this:
Find the old index with alias. Create new index and fill with new data Remove alias and delete old index Give new index alias
How we can do this using php client library.
I don't get why People are giving him down-votes, the question is straight forward, and the docs for elastic-search are not easy to follow!
Anyway here's the solution:
class SomeClass
{
/** @var \Elasticsearch\Client */
private $client;
/**
* @param \Elasticsearch\Client $client
*/
public function __construct(\Elasticsearch\Client $client)
{
$this->client = $client;
}
/**
* @param string $aliasName
*
* @return null|string
*/
public function findIndexNameByAlias($aliasName)
{
$aliases = $this->client->indices()->getAliases();
foreach ($aliases as $index => $aliasMapping) {
if (array_key_exists($aliasName, $aliasMapping['aliases'])) {
return $index;
}
}
return null;
}
}
$someClass = new SomeClass(new \Elasticsearch\Client());
echo "Index associated with 'MyAlias': " . $someClass->findIndexNameByAlias('MyAlias');
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With