代码
@Test
void getDocument() throws IOException {
//1创建GetRequest对象
GetRequest request = new GetRequest("test_es").id("56201");
SearchRequest searchRequest = new SearchRequest();
//2获取es返回内容
GetResponse response = client.get(request, RequestOptions.DEFAULT);
//3获取es查询到的数据
String source = response.getSourceAsString();
//从json类型转换成Java对象
HotelDoc hotelDoc = JSON.parseObject(source, HotelDoc.class); //**转换成Java对象失败(所有字段的值都是null)**
System.out.println("es返回的json类型:" + source);
System.out.println("hotelDoc:" + hotelDoc);
}
控制台打印出来的信息
es返回的json类型:{"{\"score\":44,\"address\":\"东方路838号\",\"business\":\"浦东陆家嘴金融贸易区\",\"city\":\"上海\",\"price\":873,\"starName\":\"四星级\",\"name\":\"上海齐鲁万怡大酒店\",\"location\":\"31.226031, 121.525801\",\"id\":56201,\"pic\":\"https://m.tuniucdn.com/fb2/t1/G6/M00/52/B6/Cii-TF3eXKeIJeN7AASiKHbTtx4AAGRegDSBzMABKJA111_w200_h200_c1_t0.jpg\",\"brand\":\"万怡\"}":"JSON"}
hotelDoc:HotelDoc(id=null, name=null, address=null, price=null, score=null, brand=null, city=null, starName=null, business=null, location=null, pic=null)