Jon*_*ado 11 php json bulk bigdata elasticsearch
我在elasticsearch中有6kk的数据需要更新.我必须使用PHP.我在文档中搜索,我发现了这个,批量索引,但这不保留以前的数据.
我有:
[
{
'name': 'Jonatahn',
'age' : 21
}
]
Run Code Online (Sandbox Code Playgroud)
我要更新的代码:
$params =[
"index" => "customer",
"type" => "doc",
"body" => [
[
"index" => [
"_index" => "customer",
"_type" => "doc",
"_id" => "09310451939"
]
],
[
"name" => "Jonathan"
]
]
];
$client->bulk($params);
Run Code Online (Sandbox Code Playgroud)
当我发送时,['name' => 'Jonathan'] 我希望名称将更新并保持年龄,但年龄已被删除.当然,我仍然可以按数据更新数据,但这需要很长时间,还有另一种方法吗?
我的错误是使用"index",但正确的方法来做我想要的,是"update".
最终的代码是:
$params =[
"index" => "customer",
"type" => "doc",
"body" => [
[
"update" => [
// ^^^^^^ Here I change from index to update
"_index" => "customer",
"_type" => "doc",
"_id" => "09310451939"
]
],
[
"doc" => [
"name" => "Jonathan"
]
]
]
];
$client->bulk($params);
Run Code Online (Sandbox Code Playgroud)
使用上面的代码,我的数据保留以前的数据,只更新我传递的参数数据.
响应:
Array
(
[took] => 7
[timed_out] =>
[_shards] => Array
(
[total] => 5
[successful] => 5
[skipped] => 0
[failed] => 0
)
[hits] => Array
(
[total] => 1
[max_score] => 1
[hits] => Array
(
[0] => Array
(
[_index] => customer
[_type] => doc
[_id] => 09310451939
[_score] => 1
[_source] => Array
(
[name] => Jonathan
[age] => 23
)
)
)
)
)
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2456 次 |
| 最近记录: |