首先说明一下为何须要批量查询操做?
假设一下好比说咱们没有批量查询的操做,那么当咱们获取数据的时候,就是一条一条的查询。设想一下咱们要获取100条数据,那么就要发送100次请求,这个开销时很大的。可是有了批量查询的话,查询100条数据,就只须要发送一次网络请求就能够了,网络请求的性能开销缩减100倍。网络
下面是实战部分,演示一下一条一条查询与批量查询:
(1)一条一条查询性能
GET /test_index/_doc/1 { "_index" : "test_index", "_type" : "_doc", "_id" : "1", "_version" : 8, "_seq_no" : 7, "_primary_term" : 1, "found" : true, "_source" : { "test_field" : "test test", "name" : "test1" } } GET /test_index/_doc/2 { "_index" : "test_index", "_type" : "_doc", "_id" : "2", "_version" : 4, "_seq_no" : 3, "_primary_term" : 1, "found" : true, "_source" : { "test_field" : "test client 1", "name" : "test1" } }
(2)mget批量查询code
GET /_mget { "docs": [ { "_index": "test_index", "_id": 1 }, { "_index": "test_index", "_id": 2 } ] } { "docs" : [ { "_index" : "test_index", "_type" : "_doc", "_id" : "1", "_version" : 8, "_seq_no" : 7, "_primary_term" : 1, "found" : true, "_source" : { "test_field" : "test test", "name" : "test1" } }, { "_index" : "test_index", "_type" : "_doc", "_id" : "2", "_version" : 4, "_seq_no" : 3, "_primary_term" : 1, "found" : true, "_source" : { "test_field" : "test client 1", "name" : "test1" } } ] }