我正在创建搜索应用程序。当我重新索引数据到elasticsearch,不应该停机,而重新索引。我想让驯鹿零停机的过程。我正在尝试这样做:
查找带有别名的旧索引。创建新索引并填充新数据删除别名并删除旧索引给出新的索引别名
我不明白为什么人们会给他投反对票,问题很直接,而且弹性搜索的文档不容易遵循!
无论如何,这是解决方案:
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');