【问题标题】:Elasticsearch PHP client throwing exception "No alive nodes found in your cluster"Elasticsearch PHP客户端抛出异常“在您的集群中找不到活动节点”
【发布时间】:2015-12-11 11:08:43
【问题描述】:

我正在尝试对索引进行扫描和滚动操作,如example 所示:

$client = ClientBuilder::create()->setHosts([MYESHOST])->build();
$params = [
    "search_type" => "scan",    // use search_type=scan
    "scroll" => "30s",          // how long between scroll requests. should be small!
    "size" => 50,               // how many results *per shard* you want back
    "index" => "my_index",
    "body" => [
        "query" => [
            "match_all" => []
        ]
    ]
];

$docs = $client->search($params);   // Execute the search
$scroll_id = $docs['_scroll_id'];   // The response will contain no results, just a _scroll_id

// Now we loop until the scroll "cursors" are exhausted
while (\true) {

    // Execute a Scroll request
    $response = $client->scroll([
            "scroll_id" => $scroll_id,  //...using our previously obtained _scroll_id
            "scroll" => "30s"           // and the same timeout window
        ]
    );

    // Check to see if we got any search hits from the scroll
    if (count($response['hits']['hits']) > 0) {
        // If yes, Do Work Here

        // Get new scroll_id
        // Must always refresh your _scroll_id!  It can change sometimes
        $scroll_id = $response['_scroll_id'];
    } else {
        // No results, scroll cursor is empty.  You've exported all the data
        break;
    }
}

第一个 $client->search($params) API 调用执行良好,我能够取回滚动 ID。但$client->scroll() API 失败,我收到异常:"Elasticsearch\Common\Exceptions\NoNodesAvailableException No alive nodes found in your cluster"

我正在使用 Elasticsearch 1.7.1 和 PHP 5.6.11

请帮忙

【问题讨论】:

  • 你有没有得到这个答案我在 localhost 上有一个找不到的节点,这很烦人。
  • @MrkFldig 没有仍然没有答案
  • 等一下,我找到了你可以尝试的东西...
  • 你试过只用主机的IP地址吗?
  • 我也面临同样的问题。您能否发布答案@ajaybc

标签: php elasticsearch php-5.6


【解决方案1】:

我发现 elasticsearch 的 php 驱动程序充满了问题,我的解决方案是通过 php 使用 curl 实现 RESTful API,一切都运行得更快,调试也更容易

【讨论】:

    【解决方案2】:

    我猜该示例与您使用的版本不是最新的(您提供的链接是 2.0,而您正在使用 1.7.1)。只需在循环内添加:

    try {
          $response = $client->scroll([
                "scroll_id" => $scroll_id,  //...using our previously obtained _scroll_id
                "scroll" => "30s"           // and the same timeout window
            ]
        );
    }catch (Elasticsearch\Common\Exceptions\NoNodesAvailableException $e) {
       break;
    }
    

    【讨论】:

    • 感谢您,这使我能够捕捉到引发的异常!
    【解决方案3】:

    检查您的服务器是否使用以下命令运行。

    service elasticsearch status
    

    我遇到了同样的问题并解决了。

    我已将 script.disable_dynamic: true 添加到 elasticsearch.yml,如 Digitalocan 教程 https://www.digitalocean.com/community/tutorials/how-to-install-and-configure-elasticsearch-on-ubuntu-14-04 中所述

    所以 elasticsearch 服务器没有启动。

    我从 elasticsearch.yml 中删除了以下行

    script.disable_dynamic: true

    【讨论】:

      【解决方案4】:

      重启elasticsearch服务并将网络主机设置为本地“127.0.0.1”。

      【讨论】:

        【解决方案5】:

        我建议直接使用 php curl lib 进行弹性搜索查询。 我发现它比任何其他 elasticsearch 客户端库都更易于使用,您可以使用 cli curl 模拟任何查询,并且您可以在互联网上找到许多示例、文档和讨论。

        【讨论】:

          【解决方案6】:

          也许你应该尝试在你的机器上远程登录 telnet [your_es_host] [your_es_ip] 检查您是否可以访问它。

          如果没有,请尝试打开该端口或禁用您机器的防火墙。

          【讨论】:

            【解决方案7】:

            该错误基本上意味着它找不到您的集群,可能是由于客户端或服务器端的配置错误。

            【讨论】:

              【解决方案8】:

              我在滚动时遇到了同样的问题,它适用于某些索引,但不适用于其他索引。在我将 elasticsearch/elasticsearch 包从 2.1.3 更新到 2.2.0 后,它一定是驱动程序中的一个错误

              【讨论】:

                【解决方案9】:

                elasticsearch.yml 中取消注释:

                network.host:198....
                

                并设置为:

                127.0.0.1
                

                像这样:

                # Set the bind address to a specific IP (IPv4 or IPv6):
                #
                 network.host: 127.0.0.1
                #
                # Set a custom port for HTTP:
                #
                # http.port: 9200
                #
                

                我在 LXC 容器下的 Magento 2 中使用 Elasticsearch 2.2

                【讨论】:

                  【解决方案10】:

                  我在 docker 中设置 Elasticsearch 服务器作为文档,https://www.elastic.co/guide/en/elasticsearch/reference/current/docker.html

                  但它使用不同的网络(网络:- esnet),它无法与应用程序网络通信。删除网络设置后,它运行良好。

                  【讨论】:

                    【解决方案11】:

                    如果您在 docker 中将 Elasticsearch 服务器设置为文档,https://www.elastic.co/guide/en/elasticsearch/reference/current/docker.html

                    但它使用与其他服务不同的网络(网络:- esnet),它无法与应用程序网络通信。删除网络设置后,它运行良好。

                    【讨论】:

                      【解决方案12】:

                      试试:

                      1. 如果您的 elasticsearch 服务已经在运行,请停止它
                      2. 通过终端进入你的elasticsearch目录,运行:

                        > ./bin/elasticsearch
                        

                      这对我有用。

                      【讨论】:

                        猜你喜欢
                        • 2016-05-04
                        • 2020-06-14
                        • 1970-01-01
                        • 2021-01-04
                        • 1970-01-01
                        • 2018-01-17
                        • 2021-03-23
                        • 1970-01-01
                        • 1970-01-01
                        相关资源
                        最近更新 更多