2015-09-15 76 views
28

我试图做一个索引扫描和滚动操作,如图中的“在集群中没有发现活节点”的exampleElasticsearch PHP客户端引发异常

$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 \例外\ NoNodesAvailableException在集群中没有发现活节点”

我使用Elasticsearch 1.7.1和PHP 5.6.11

请帮助

+0

你有没有得到答案,我有一个本地节点无法找到,这是相当烦人。 –

+0

@MrkFldig还没有人回答 – ajaybc

+0

等待我发现了一些你可以尝试的东西... –

回答

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; 
} 
+0

感谢您的支持,这使我能够捕捉到异常情况! –

0

取消注释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 
# 

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

1

我会推荐使用php curl lib直接用于elasticsearch查询。 我发现它比任何其他elasticsearch客户端库更容易使用,您可以使用cli curl来模拟任何查询,并且您可以在互联网中找到许多示例,文档和讨论。

0

我曾与滚动同样的问题,它与某些指标的工作,但不与他人删除以下行。当我更新2.1.3至2.2.0的elasticsearch/elasticsearch包后,它一定是驱动程序中的一个bug。

1

重新启动弹性搜索服务并将网络主机设置为本地“127.0.0.1 ”。

2

我发现elasticsearch的PHP驱动程序是充满了问题,我是刚刚实施的RESTful API通过PHP卷曲的解决方案,一切工作要快得多,调试容易得多

1

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

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

1

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