es之java搜索文档

1:搜索文档数据(单个索引)

@Test
public void getSingleDocument(){
    GetResponse response = client.prepareGet("twitter", "tweet", "1").get();
    System.out.println(response.toString());
}

2:搜索文档数据(多个索引)

@Test
public void getMutileDocument(){
    MultiGetResponse multiGetResponse = client.prepareMultiGet()
            .add("twitter1" , "tweet" , "1")
            .add("twitter2" , "tweet" , "1")
            .add("twitter3" , "tweet" , "1")
            .add("twitter4" , "tweet" , "1","2","3")
            .get();
    for (MultiGetItemResponse itemResponse : multiGetResponse) {
        GetResponse response = itemResponse.getResponse();
        if (response.isExists()) {
            String sourceAsString = response.toString();
            System.out.println(sourceAsString);
        }
    }

}

 

posted @ 2017-05-22 23:17  niutao  阅读(669)  评论(0编辑  收藏  举报