ES7.x批量插入数据
这是以书来举列子
我们先看restful的写法
写完之后千万记得换行,记得换行,记得换行,重要事情说3遍
POST XXX/_bulk
{"create":{"_index":"dangdang","_type":"_doc","_id":"123"}}
{"book_name":"php","book_img":"963.jpg","subtitle":"没有副标题","detail":"没有更多详细","price":"32"}
{"create":{"_index":"dangdang","_type":"_doc","_id":"124"}}
{"book_name":"php","book_img":"963.jpg","subtitle":"没有副标题","detail":"没有更多详细","price":"32"}
之后我们来看PHP的写法
$es_params = [
'body'=>[
['create'=>['_index'=>'dangdang','_id'=>'123']],
["book_name"=>"php","book_img"=>"963.jpg","subtitle"=>"没有副标题","detail"=>"没有更多详细","price"=>"32"],
['create'=>['_index'=>'dangdang','_id'=>'124']]],
["book_name"=>"php","book_img"=>"963.jpg","subtitle"=>"没有副标题","detail"=>"没有更多详细","price"=>"32"],
]
]
$ClientBuilder = new ClientBuilder();
$client = $ClientBuilder->setHosts(['xxx.xxx.xxx.xxx:9200'])->build();
$response = $client->bulk($es_params);
知识源于学习