1. @SpringBootTest
    2. public class MyTest{
    3. //注入RestHighLevelClient对象
    4. @Autowired
    5. private RestHighLevelClient restHighLevelClient;
    6. @Test
    7. public void test() throws IOException {
    8. //准备GetRequest请求对象,并指定索引库名和文档id
    9. GetRequest getRequest = new GetRequest(索引库名, 文档id);
    10. //发送请求,得到响应对象
    11. GetResponse getResponse = restHighLevelClient.get(getRequest, RequestOptions.DEFAULT);
    12. //获取响应对象中的Json数据
    13. String json = getResponse.getSourceAsString();
    14. //反序列化Json,这里需要引入fastjson的依赖
    15. 类名 对象名 = JSON.parseObject(json, 类名.class);
    16. }
    17. }