2015-09-15 73 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

該錯誤基本上意味着它無法找到您的羣集,可能是由於客戶端或服務器端的配置錯誤。