美文网首页
ES高级客户端HighLevelClient

ES高级客户端HighLevelClient

作者: Binary_r | 来源:发表于2020-12-25 17:41 被阅读0次

    根据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());
                }
            }
    

    相关文章

      网友评论

          本文标题:ES高级客户端HighLevelClient

          本文链接:https://www.haomeiwen.com/subject/vodinktx.html