2017-04-19 145 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); 

后,这是不这样做的最佳方式,但为我工作的唯一。