dig*_*tum 5 java elasticsearch
我想要一种简单的方法来验证ES客户端是否可以使用ES.我有一个看起来像这样的工厂来获取客户端实例:
https://gist.github.com/1364734
什么是优雅地处理ES无法使用的场景或者我有足够的最佳方式?
谢伊此前证实,这种方法是一个很好的方法。该方法也得到了文档的支持。
至于优雅的处理。您应该只对尝试执行搜索的请求或进程出错。有可能TransportClient已连接并且未来的请求可能会成功。
为了完整起见,在此处复制您的函数。
Run Code Online (Sandbox Code Playgroud)private void verifyConnection(TransportClient client) { ImmutableList<DiscoveryNode> nodes = client.connectedNodes(); if (nodes.isEmpty()) { throw new ElasticSearchUnavailableException("No nodes available. Verify ES is running!"); } else { log.info("connected to nodes: " + nodes.toString()); } }
来自https://gist.github.com/1364734
| 归档时间: |
|
| 查看次数: |
5339 次 |
| 最近记录: |