public function batchCreateDoc(array $items, $index_name) {
$params = ['body' => []];
foreach ($items as $item) {
$id = getValue($item, 'id');
if (!$id) {
throw new \RuntimeException('批量更新必须包含 id 属性');
}
$params['body'][] = [
'index' => [
'_index' => $index_name,
'_type' => $index_name,
'_id' => $id
]
];
$params['body'][] = $item;
}
return $this->client->bulk($params);
}
$data = $es->batchCreateDoc([
['id' => 'b2fd0dc6e0b0857422d6b5ad3dddd61411', 'status' => 1]
], 'xxxx');
print_r($data);
- 更新完后 id=b2fd0dc6e0b0857422d6b5ad3dddd61411 的文档只有 status 字段 这 Id 是存在的,非创建
- 更新前有 N 个字段都没有了,这是哪问题