2016-08-23 129 views
2

我正在创建搜索应用程序。当我将数据重新索引到elasticsearch时,重新索引时不应该停机。我想让零宕机时间的reindexing进程。我试图这样做:如何在Elasticsearch php客户端API中查找别名索引

找到带有别名的旧索引。 创建新的索引,并用新的数据填充 删除别名并删除旧索引 给新指数别名

我们怎样才能做到这一点使用PHP客户端库。

+0

请分享一些代码,以帮助我们来帮助你 – legrandviking

+0

欢迎StackOverflow上。请阅读并遵守帮助文档中的发布准则。 [最小,完整,可验证的示例](http://stackoverflow.com/help/mcve)适用于此处。在您发布代码并准确描述问题之前,我们无法有效帮助您。 StackOverflow不是一个编码或教程服务。 – Prune

回答

1

我不明白为什么人们给他的是低票,问题很简单,弹性搜索的文档不容易遵循!

反正这里的解决方案:

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'); 
相关问题