1、bulk语法

可操作的类型

  1. delete 删除一个文档,只要一个json就可以进行操作
  2. create put /index/_create/id 强制创建
  3. index 普通的put操作,可以创建文档,也可以时全量替换文档
  4. update 执行partial update操作

bulk 批量操作,一条错误,不会影响其他条目的更新,在返回时会给出异常

  1. POST /_bulk #一个json为一行,不能换多行
  2. {"delete":{"_index":"bobotest","_id":"3"}}
  3. {"create":{"_index":"bobotest","_id":"3"}}
  4. {"filed":"wuyifanshuaige"}
  5. {"index":{"_index":"bobotest","_id":"2"}}
  6. {"filed":"test2"}
  7. {"update":{"_index":"bobotest","_id":"4"}}
  8. {"doc":{"filed":"test4"}}
  9. GET /bobotest/_mget
  10. {
  11. "docs":[
  12. {
  13. "_index":"bobotest",
  14. "_id":2
  15. },
  16. {
  17. "_index":"bobotest",
  18. "_id":3
  19. },
  20. {
  21. "_index":"bobotest",
  22. "_id":4
  23. }
  24. ]
  25. }

2、bulk性能优化

bulk request 会加载到内存中,如果太大,性能反而会有影响,因此要尝试一个最佳的bulk size.一般从1000-5000条数据开始。尝试逐渐增加,看大小,最好在5M-15M之间