mget是很重要的,一般来说,在进行查询的时候,如果一次性要查询多条数据的话,那么一定要用batch批量操作的api,尽可能减少网络开销次数,可以将性能提升数倍,甚至数十倍
1.mget批量查询
GET /_mget
{
"docs" : [
{
"_index" : "test_index",
"_type" : "test_type",
"_id" : 1
},
{
"_index" : "test_index",
"_type" : "test_type",
"_id" : 2
}
]
}
(2)查询一个index下的不同type的document
GET /test_index/_mget
{
"docs" : [
{
"_type" : "test_type",
"_id" : 1
},
{
"_type" : "test_type",
"_id" : 2
}
]
}
(3)查询的数据都在同一个index下的同一个type下
GET /test_index/test_type/_mget
{
"ids": [1, 2]
}
from elasticsearch import Elasticsearch
es = Elasticsearch(hosts="ip:port")
# 使用python进行mget操作
result = es.mget(body=body, index=None, doc_type=None)
"""
result = es.transport.perform_request(
"GET", _make_path(None, None, "_mget"), params=None, body=body
)
"""