當(dāng)前位置:
首頁 >
批量查询,mget语法,mget批量查询(来自学习资料,第26节)
發(fā)布時間:2024/9/27
32
豆豆
生活随笔
收集整理的這篇文章主要介紹了
批量查询,mget语法,mget批量查询(来自学习资料,第26节)
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
1、批量查詢的好處
一條一條的查詢,比如說要查詢100條數(shù)據(jù),那么就要發(fā)送100次網(wǎng)絡(luò)請求,這個開銷還是很大的
如果進(jìn)行批量查詢的話,查詢100條數(shù)據(jù),就只要發(fā)送1次網(wǎng)絡(luò)請求,網(wǎng)絡(luò)請求的性能開銷縮減100倍,這時候就可以使用mget來完成這個目標(biāo)
2、mget的語法
(1)一條一條的查詢
GET /test_index/test_type/1運(yùn)行的結(jié)果是:
{"_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運(yùn)行的結(jié)果是:
{"_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}] }查詢結(jié)果:
{"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)如果查詢的數(shù)據(jù)都在同一個index下的同一個type下,最簡單了
查詢語句
GET /test_index/test_type/_mget {"ids": [1, 2] }3、mget的重要性
可以說mget是很重要的,一般來說,在進(jìn)行查詢的時候,如果一次性要查詢多條數(shù)據(jù)的話,那么一定要用batch批量操作的api
盡可能減少網(wǎng)絡(luò)開銷次數(shù),可能可以將性能提升數(shù)倍,甚至數(shù)十倍,非常非常之重要
總結(jié)
以上是生活随笔為你收集整理的批量查询,mget语法,mget批量查询(来自学习资料,第26节)的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 为什么很多车主习惯关闭自动启停功能?
- 下一篇: 发动机冒黑烟的检测步骤?