ES高级客户端HighLevelClient

2020-12-25  本文已影响0人  Binary_r

根据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());
            }
        }
上一篇下一篇

猜你喜欢

热点阅读