09.multi-get api操作
生活随笔
收集整理的這篇文章主要介紹了
09.multi-get api操作
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
文章目錄
- 1. 多個 GET API
- 2. Source filtering
- 3. Fields
- 4. Routing
1. 多個 GET API
多 GET API 允許基于索引,類型(可選)和ID(也可能路由)獲取多個文檔。響應包括獲取的 docs 列表,每個文件的結構都類似于 GET API 提供文件的結構。下面是一個例子:
GET /_mget {"docs" : [{"_index" : "test","_type" : "_doc","_id" : "1"},{"_index" : "test","_type" : "_doc","_id" : "2"}] }mget也可以針對一個索引(在 body 體中不需要index名稱):
GET /test/_mget {"docs" : [{"_type" : "_doc","_id" : "1"},{"_type" : "_doc","_id" : "2"}] }類型如下:
GET /test/_doc/_mget {"docs" : [{"_id" : "1"},{"_id" : "2"}] }在這種情況下,id 可以被用作發起簡單的請求:
GET /test/_doc/_mget {"ids" : ["1", "2"] }2. Source filtering
默認情況下,每個文檔返回_source(如果儲存)。類似于 GET API,你可以檢索的只是部分 _source,使用 _source參數。您還可以使用URL參數 _source,_source_include及_source_exclude 來指定默認值。例如:
GET /_mget {"docs" : [{"_index" : "test","_type" : "_doc","_id" : "1","_source" : false},{"_index" : "test","_type" : "_doc","_id" : "2","_source" : ["field3", "field4"]},{"_index" : "test","_type" : "_doc","_id" : "3","_source" : {"include": ["user"],"exclude": ["user.location"]}}] }3. Fields
通過每個文檔來可以指定具體存儲字段,類似于 Get API 中 stored_fields 參數。例如:
GET /_mget {"docs" : [{"_index" : "test","_type" : "_doc","_id" : "1","stored_fields" : ["field1", "field2"]},{"_index" : "test","_type" : "_doc","_id" : "2","stored_fields" : ["field3", "field4"]}] }或者,可以指定 stored_fields作為默認值被應用到所有文件中來查詢字符串參數。
GET /test/_doc/_mget?stored_fields=field1,field2 {"docs" : [{"_id" : "1" },{"_id" : "2","stored_fields" : ["field3", "field4"] }] }(1)返回 field1和 field2
(2)返回 field3和 field4
4. Routing
您也可以指定 routing 作為參數:
GET /_mget?routing=key1 {"docs" : [{"_index" : "test","_type" : "_doc","_id" : "1","routing" : "key2"},{"_index" : "test","_type" : "_doc","_id" : "2"}] }在這個例子中,doc id 為2的doc 會從 routing = key1 的分片中獲取。但文件 doc id 1的doc 將被從對應于 routing = key1 的分片中獲取。
總結
以上是生活随笔為你收集整理的09.multi-get api操作的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 08.update_by_query操作
- 下一篇: 10.bulk操作