好,我想出了一个解决方案。由于Java客户端的调用是异步完成的,因此您必须使用带有操作侦听器的变体。解决方案仍然有些人为的:
// Inner class because it's just used to be thrown out of// the action listener implementation to signal that the// index existsprivate class ExistsException extends RuntimeException {}public boolean exists() { logger.info(String.format("Verifying existence of index "%s"", indexName)); IndicesExistsRequest request = new IndicesExistsRequest(indexName); try { adminClient.exists(request, new ActionListener<IndicesExistsResponse>() { public void onResponse(IndicesExistsResponse response) { if (response.isExists()) { throw new ExistsException(); } } public void onFailure(Throwable e) { ExceptionUtil.smash(e); } }); } catch (ExistsException e) { return true; } return false;}


