
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); 1 zhuangjia 2022-10-25 19:55:16 +08:00 看了下文档: https://www.elastic.co/guide/en/elasticsearch/reference/6.7/docs-bulk.html 提示如下: i.e. create will fail if a document with the same index and type exists already, whereas index will add or replace a document as necessary 存在的时候是 [替换] 而不是 [更新] |
2 zzl22100048 2022-10-25 22:15:20 +08:00 via iPhone 你需要 update ,index 会覆盖 |