⑤. ES的批量操作——bulk
这里的批量操作,当发生某一条执行发生失败时,其他的数据仍然能够接着执行,也就是说彼此之间是独立的
实例1: 执行多条数据 POST /customer/external/_bulk {"index":{"_id":"1"}} {"name":"John Doe"} {"index":{"_id":"2"}} {"name":"John Doe"} #! Deprecation: [types removal] Specifying types in bulk requests is deprecated. { "took" : 318, 花费了多少ms "errors" : false, 没有发生任何错误 "items" : [ 每个数据的结果 { "index" : { 保存 "_index" : "customer", 索引 "_type" : "external", 类型 "_id" : "1", 文档 "_version" : 1, 版本 "result" : "created", 创建 "_shards" : { "total" : 2, "successful" : 1, "failed" : 0 }, "_seq_no" : 0, "_primary_term" : 1, "status" : 201 新建完成 } }, { "index" : { 第二条记录 "_index" : "customer", "_type" : "external", "_id" : "2", "_version" : 1, "result" : "created", "_shards" : { "total" : 2, "successful" : 1, "failed" : 0 }, "_seq_no" : 1, "_primary_term" : 1, "status" : 201 } } ] }
实例2:对于整个索引执行批量操作 POST /_bulk {"delete":{"_index":"website","_type":"blog","_id":"123"}} {"create":{"_index":"website","_type":"blog","_id":"123"}} {"title":"my first blog post"} {"index":{"_index":"website","_type":"blog"}} {"title":"my second blog post"} {"update":{"_index":"website","_type":"blog","_id":"123"}} {"doc":{"title":"my updated blog post"}} 运行结果: #! Deprecation: [types removal] Specifying types in bulk requests is deprecated. { "took" : 304, "errors" : false, "items" : [ { "delete" : { 删除 "_index" : "website", "_type" : "blog", "_id" : "123", "_version" : 1, "result" : "not_found", 没有该记录 "_shards" : { "total" : 2, "successful" : 1, "failed" : 0 }, "_seq_no" : 0, "_primary_term" : 1, "status" : 404 没有该 } }, { "create" : { 创建 "_index" : "website", "_type" : "blog", "_id" : "123", "_version" : 2, "result" : "created", "_shards" : { "total" : 2, "successful" : 1, "failed" : 0 }, "_seq_no" : 1, "_primary_term" : 1, "status" : 201 } }, { "index" : { 保存 "_index" : "website", "_type" : "blog", "_id" : "5sKNvncBKdY1wAQmeQNo", "_version" : 1, "result" : "created", "_shards" : { "total" : 2, "successful" : 1, "failed" : 0 }, "_seq_no" : 2, "_primary_term" : 1, "status" : 201 } }, { "update" : { 更新 "_index" : "website", "_type" : "blog", "_id" : "123", "_version" : 3, "result" : "updated", "_shards" : { "total" : 2, "successful" : 1, "failed" : 0 }, "_seq_no" : 3, "_primary_term" : 1, "status" : 200 } } ] }
⑥. 样本测试数据(有1000条数据)
https://github.com/elastic/elasticsearch/blob/v7.4.2/docs/src/test/resources/accounts.json
链接:https://pan.baidu.com/s/1my-luYGAsGrCnyxNve_6Hw 提取码:1234