【发布时间】:2016-01-22 02:37:10
【问题描述】:
我创建了一个带有映射的新索引。其中存储了 500 000 个文档。
我想更改索引的映射,但在弹性搜索中不可能。所以我用新的新映射创建了另一个索引,现在我试图将文档从旧索引复制到新索引。
我正在使用扫描和滚动类型从旧索引中检索文档并复制到新索引。因为复制需要更多时间并且系统速度变慢。
下面是我正在使用的代码。
$client= app('elastic_search');
$params = [
"search_type" => "scan", // use search_type=scan
"scroll" => "30s", // how long between scroll requests. should be small!
"size" => 500000, // how many results *per shard* you want back
"index" => "admin_logs422",
"body" => [
"query" => [
"match_all" => []
]
]
];
$docs = $client->search($params); // Execute the search
$scroll_id = $docs['_scroll_id'];
while (\true) {
// Execute a Scroll request
$response = $client->scroll([
"scroll_id" => $scroll_id, //...using our previously obtained _scroll_id
"scroll" => "500s" // and the same timeout window
]
);
if (count($response['hits']['hits']) > 0) {
foreach($response['hits']['hits'] as $s)
{
$params =
[
'index' => 'admin_logs421',
'type' => 'admin_type421',
'id'=> $s['_id'],
'client' => [
'ignore' => [400, 404],
'verbose' => true,
'timeout' => 10,
'connect_timeout' => 10
],
'body' => $s['_source']
];
$response = app('elastic_search')->create($params);
}
$scroll_id = $response['_scroll_id'];
} else {
// No results, scroll cursor is empty. You've exported all the data
return response("completed");
}
}
【问题讨论】:
标签: elasticsearch