【问题标题】:How to find Index by Alias in Elasticsearch php client api如何在 Elasticsearch php 客户端 api 中按别名查找索引
【发布时间】:2016-12-30 05:06:38
【问题描述】:

我正在创建搜索应用程序。当我将数据重新索引到弹性搜索中时,重新索引时不应该停机。我想以零停机时间进行重新索引过程。我正在尝试这样做:

使用别名查找旧索引。 创建新索引并填充新数据 删除别名并删除旧索引 给新的索引别名

我们如何使用 php 客户端库来做到这一点。

【问题讨论】:

  • 请分享一些代码来帮助我们帮助你
  • 欢迎来到 StackOverflow。请阅读并遵循帮助文档中的发布指南。 Minimal, complete, verifiable example 适用于此。在您发布代码并准确描述问题之前,我们无法有效地帮助您。 StackOverflow 不是编码或教程服务。

标签: php search elasticsearch


【解决方案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');

【讨论】:

    猜你喜欢
    • 2014-10-10
    • 2016-12-28
    • 2016-12-29
    • 2018-10-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-11-10
    • 1970-01-01
    相关资源
    最近更新 更多