2017-04-19 68 views
0

我需要儘可能快地索引大約1000個文檔。我決定使用大約比原始解決方案快10倍的批量功能。我需要在索引結束後立即輸入refresh以使文檔可搜索。在其他情況下,我會使用刷新參數'refresh'=> true,但我不能讓它在PHP中使用批量。我使用code from official documentationElasticSearch - 帶刷新的批量索引

for($i = 0; $i < 100; $i++) { 
    $params['body'][] = [ 
     'index' => [ 
      '_index' => 'my_index', 
      '_type' => 'my_type', 
     ] 
    ]; 

    $params['body'][] = [ 
     'my_field' => 'my_value', 
     'second_field' => 'some more values' 
    ]; 
} 

$responses = $client->bulk($params); 

在PHP批量函數中使用刷新的正確方法是什麼?

回答

0

我用假的更新操作與刷新右散裝

$params = [ 
    'index' => 'my_index', 
    'type' => 'refresh', 
    'id' => 'refresh', 
    'refresh' => true,    // REFRESH 
    'body' => [] 
]; 

$client->index($params); 

後,這是不這樣做的最佳方式,但爲我工作的唯一。

相關問題