ElasticSearch(七) Multi Get API

一、根据索引、类型、ID 获取多文档

MultiGetResponse multiGetItemResponses = client.prepareMultiGet()
.add("twitter", "tweet", "1")
.add("twitter", "tweet", "2", "3", "4")     //多id 列表
.add("another", "type", "foo")              //查询其他索引
.get();

for (MultiGetItemResponse itemResponse : multiGetItemResponses) {
GetResponse response = itemResponse.getResponse();
if (response.isExists()) {
String json = response.getSourceAsString();
}
}

posted @ 2017-12-26 16:58  小蚕豆  阅读(759)  评论(0编辑  收藏  举报