php操作ElasticSearch7.x bulk,批量插入数据

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);

知识源于学习

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值