批量查询,mget语法,mget批量查询(来自学习资料,第26节)
生活随笔
收集整理的這篇文章主要介紹了
批量查询,mget语法,mget批量查询(来自学习资料,第26节)
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
1、批量查詢的好處
一條一條的查詢,比如說要查詢100條數據,那么就要發送100次網絡請求,這個開銷還是很大的
如果進行批量查詢的話,查詢100條數據,就只要發送1次網絡請求,網絡請求的性能開銷縮減100倍,這時候就可以使用mget來完成這個目標
2、mget的語法
(1)一條一條的查詢
GET /test_index/test_type/1運行的結果是:
{"_index": "test_index","_type": "test_type","_id": "1","_version": 2,"found": true,"_source": {"test_field1": "test field1","test_field2": "test field2"} }再如:
GET /test_index/test_type/2運行的結果是:
{"_index": "test_index","_type": "test_type","_id": "2","_version": 1,"found": true,"_source": {"test_content": "my test"} }(2)mget批量查詢
查詢語句:
GET /_mget {"docs" : [{"_index" : "test_index","_type" : "test_type","_id" : 1},{"_index" : "test_index","_type" : "test_type","_id" : 2}] }查詢結果:
{"docs": [{"_index": "test_index","_type": "test_type","_id": "1","_version": 2,"found": true,"_source": {"test_field1": "test field1","test_field2": "test field2"}},{"_index": "test_index","_type": "test_type","_id": "2","_version": 1,"found": true,"_source": {"test_content": "my test"}}] }(3)如果查詢的document是一個index下的不同type種的話
查詢語句: {"docs": [{"_index": "test_index","_type": "test_type","_id": "1","_version": 2,"found": true,"_source": {"test_field1": "test field1","test_field2": "test field2"}},{"_index": "test_index","_type": "test_type","_id": "2","_version": 1,"found": true,"_source": {"test_content": "my test"}}] }(4)如果查詢的數據都在同一個index下的同一個type下,最簡單了
查詢語句
GET /test_index/test_type/_mget {"ids": [1, 2] }3、mget的重要性
可以說mget是很重要的,一般來說,在進行查詢的時候,如果一次性要查詢多條數據的話,那么一定要用batch批量操作的api
盡可能減少網絡開銷次數,可能可以將性能提升數倍,甚至數十倍,非常非常之重要
總結
以上是生活随笔為你收集整理的批量查询,mget语法,mget批量查询(来自学习资料,第26节)的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 为什么很多车主习惯关闭自动启停功能?
- 下一篇: 发动机冒黑烟的检测步骤?