簡體   English   中英

ElasticSearch-帶有刷新的批量索引

[英]ElasticSearch - Bulk Indexing with refresh

我需要盡快索引約1000個文檔。 我決定使用批量功能,該功能的運行速度比原始解決方案快約10倍。 我需要在索引結束后立即刷新以使文檔可搜索。 在其他情況下,我將使用刷新參數'refresh'=> true,但是我無法使其在PHP中與批量工作。 我使用官方文檔中的代碼

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批量功能中使用刷新的正確方法是什么?

我在批量之后立即使用偽造的更新操作進行刷新

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

$client->index($params);

這不是最好的方法,而是唯一對我有用的方法。

只需添加

$params['refresh'] = true;

循環之后和批量插入之前。

所以最終的代碼是

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'
    ];
}

$params['refresh'] = true;
$responses = $client->bulk($params);

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM