Bulk批量操作API的介绍
生活随笔
收集整理的這篇文章主要介紹了
Bulk批量操作API的介绍
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
?
?
?
#多重模式 #批量操作bulk POST /library/books/_bulk {"index": {"_id": 1}} {"title":"Elasticsearch: The Definitive Guide","price":5} {"index": {"_id": 2}} {"title":"The Elasticsearch cookbook","price":15 } {"index": {"_id": 3}} {"title":"Elosticsearch Blueprints","price":9 } {"index": {"_id": 4}} {"title":"Thinking in Python","price":22 } {"index": {"_id": 5}} {"title":"Thinking in Java","price":7 }?
?
?
#通過id批量獲取
GET /library/books/_mget {"ids":["1","2","3","4","5"] }返回結果
{"docs" : [{"_index" : "library","_type" : "books","_id" : "1","_version" : 1,"_seq_no" : 0,"_primary_term" : 1,"found" : true,"_source" : {"title" : "Elasticsearch: The Definitive Guide","price" : 5}},{"_index" : "library","_type" : "books","_id" : "2","_version" : 1,"_seq_no" : 0,"_primary_term" : 1,"found" : true,"_source" : {"title" : "The Elasticsearch cookbook","price" : 15}},{"_index" : "library","_type" : "books","_id" : "3","_version" : 1,"_seq_no" : 0,"_primary_term" : 1,"found" : true,"_source" : {"title" : "Elosticsearch Blueprints","price" : 9}},{"_index" : "library","_type" : "books","_id" : "4","_version" : 1,"_seq_no" : 1,"_primary_term" : 1,"found" : true,"_source" : {"title" : "Thinking in Python","price" : 22}},{"_index" : "library","_type" : "books","_id" : "5","_version" : 1,"_seq_no" : 0,"_primary_term" : 1,"found" : true,"_source" : {"title" : "Thinking in Java","price" : 7}}] } #當然注意還可以有delete,update等操作 #注意delete下面沒有具體的request body POST /library/books/_bulk {"delete": {"_index": "library", "_type": "books","_id": "1"}} {"create": {"_index": "music", "_type": "classical","_id":"2"}} {"title": "Ave Verus Corpus" } {"index": {"_index": "music", "_type": "classical"}} {"title": "Litaniac de Venerabili Altaris Sacromento"} {"update": {"_index": "library", "_type": "books", "_id": "2"}} {"doc" : {"price" :"18"} }執行批量操作后返回結果
{"took" : 43,"errors" : false,"items" : [{"delete" : {"_index" : "library","_type" : "books","_id" : "1","_version" : 5,"result" : "not_found","_shards" : {"total" : 2,"successful" : 1,"failed" : 0},"_seq_no" : 4,"_primary_term" : 1,"status" : 404}},{"create" : {"_index" : "music","_type" : "classical","_id" : "2","_version" : 1,"result" : "created","_shards" : {"total" : 2,"successful" : 1,"failed" : 0},"_seq_no" : 1,"_primary_term" : 1,"status" : 201}},{"index" : {"_index" : "music","_type" : "classical","_id" : "cVIUunABRyQ6qH3OTcbo","_version" : 1,"result" : "created","_shards" : {"total" : 2,"successful" : 1,"failed" : 0},"_seq_no" : 1,"_primary_term" : 1,"status" : 201}},{"update" : {"_index" : "library","_type" : "books","_id" : "2","_version" : 3,"result" : "noop","_shards" : {"total" : 2,"successful" : 1,"failed" : 0},"status" : 200}}] }?
結果分析執行都成功了,先看下下刪除是不是成功
GET /library/books/1
批量返回結果分析:
{"docs" : [{"_index" : "library","_type" : "books","_id" : "1","found" : false},{"_index" : "library","_type" : "books","_id" : "2","_version" : 3,"_seq_no" : 4,"_primary_term" : 1,"found" : true,"_source" : {"title" : "The Elasticsearch cookbook","price" : "18"}},{"_index" : "library","_type" : "books","_id" : "3","_version" : 2,"_seq_no" : 1,"_primary_term" : 1,"found" : true,"_source" : {"title" : "Elasticsearch Blueprints","price" : 9}},{"_index" : "library","_type" : "books","_id" : "4","_version" : 2,"_seq_no" : 3,"_primary_term" : 1,"found" : true,"_source" : {"title" : "Thinking in Python","price" : 22}},{"_index" : "library","_type" : "books","_id" : "5","_version" : 2,"_seq_no" : 1,"_primary_term" : 1,"found" : true,"_source" : {"title" : "Thinking in Java","price" : 7}}] }?
我們還創建了一個music,獲取下驗證是否成功
?
總結
以上是生活随笔為你收集整理的Bulk批量操作API的介绍的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: ifstream 和 ofstream
- 下一篇: docker 无法正常启动或版本信息会报