根据ID批量查询
RestHighLevelClient client = new RestHighLevelClient(xxxx);
MultiGetRequest request = new MultiGetRequest();
request.add(new MultiGetRequest.Item("goods", "nl9KbnUBhA6egNFAEcIM"));
request.add(new MultiGetRequest.Item("goods", "uV9KbnUBhA6egNFAMsJg"));
request.add(new MultiGetRequest.Item("goods", "123"));
MultiGetResponse responses = client.mget(request, RequestOptions.DEFAULT);
MultiGetItemResponse[] responses1 = responses.getResponses();
for (MultiGetItemResponse multiGetItemResponse : responses1) {
//System.out.println(JSON.toJSONString(multiGetItemResponse));
if (multiGetItemResponse.getResponse().isExists()){
String s = JSON.toJSONString(multiGetItemResponse.getResponse().getSource());
System.out.println(JSON.parseObject(s, Goods.class));
}else{
System.out.println(multiGetItemResponse.getResponse().getId());
}
}
网友评论