1. @SpringBootTest
    2. public class MyTest{
    3. //注入RestHighLevelClient对象
    4. @Autowired
    5. private RestHighLevelClient restHighLevelClient;
    6. @Test
    7. public void test() throws IOException {
    8. //创建GetIndexRequest请求对象,并指定索引库名
    9. GetIndexRequest getIndexRequest = new GetIndexRequest(索引库名);
    10. //发送请求,得到响应
    11. boolean isExist = restHighLevelClient.indices().exists(getIndexRequest, RequestOptions.DEFAULT);
    12. //输出结果
    13. System.err.println(isExist ? "索引库已存在" : "索引库不存在");
    14. }
    15. }