打开、关闭连接代价比较高,尽量把多个操作放在一个请求中完成,来提升性能。

 

 

批量插入文档

POST mall/_doc/_bulk
{ "index":{} }
{ "goods_name":"苹果","goods_price":10.0,"goods_description":"新鲜苹果,10元一斤" }
{ "index":{} }
{ "goods_name":"梨子","goods_price":5.0,"goods_description":"新鲜梨子,5元一斤" }

2行表示一个文档

在url中指定index、type,文档id自动生成。

 

 

也可以手动指定文档id:

POST mall/_doc/_bulk
{ "index":{"_id":"1"} }
{ "goods_name":"苹果","goods_price":10.0,"goods_description":"新鲜苹果,10元一斤" }
{ "index":{"_id":"2"} }
{ "goods_name":"梨子","goods_price":5.0,"goods_description":"新鲜梨子,5元一斤" }

 

 

index、type、id都可以写在“index”中:

POST _bulk
{ "index":{"_index":"mall","_type":"_doc","_id":"1"} }
{ "goods_name":"冬瓜","goods_price":5.0,"goods_description":"新鲜冬瓜,5元一斤" }
{ "index":{"_index":"mall","_type":"_doc","_id":"2"} }
{ "goods_name":"西瓜","goods_price":5.0,"goods_description":"新鲜西瓜,5元一斤" }

要么写在“index”中,要么写在url中,总之要指定index、type。在“index”中指定时有前缀_

id可以不指定,会自动生成。

 

 

用PUT、POST都行,对document来说是新建,对index、type来说是更新。

 

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-11-04
  • 2022-01-17
  • 2022-01-16
  • 2021-09-18
  • 2022-12-23
猜你喜欢
  • 2021-12-09
  • 2021-08-21
  • 2022-12-23
  • 2021-10-07
  • 2021-10-29
相关资源
相似解决方案