ElasticSearchUtils { public static boolean indexExist(RestHighLevelClient client, String indexName) { try { GetIndexRequest request = new GetIndexRequest(indexName); return client.indices().exists(request, RequestOptions.DEFAULT); } catch(Exception e) { if(log.isErrorEnabled()) { log.error("Error Checking Index Exist", e); } throw new IndicesExistsFailedException(indexName, e); } } private  ElasticSearchUtils(); static boolean indexExist(RestHighLevelClient client, String indexName); static boolean mappingsExist(RestHighLevelClient client, String indexName); static CreateIndexResponse createIndex(RestHighLevelClient client, String indexName); static void createOrUpdatemapping(RestHighLevelClient client, String indexName, IElasticSearchMapping mapping); static AcknowledgedResponse putMapping(RestHighLevelClient client, String indexName, IElasticSearchMapping mapping); static AcknowledgedResponse updateMapping(RestHighLevelClient client, String indexName, IElasticSearchMapping mapping);  }
@Test public void indices_exist_throws_correct_exception_when_underlying_client_throws() throws Exception { when(client.indices()).thenThrow(new RuntimeException()); TestUtils.assertThrows(() -> ElasticSearchUtils.indexExist(client, ""), IndicesExistsFailedException.class); }