背景:项目要同时引入
org.elasticsearch elasticsearchorg.elasticsearch.client elasticsearch-rest-high-level-client
需要用到elasticsearch低版本依赖(高版本该类过时)的TransportClient类,来获取索引的数据量大小(elasticsearch-rest-high-level-client依赖没有这个api),
同时因为之前代码都使用elasticsearch-rest-high-level-client依赖进行写,所以尽可能不改动。
问题:高版本elasticsearch依赖过时,elasticsearch-rest-high-level-client又没有获取索引的数据量大小的api,且elasticsearch-rest-high-level-client内部自带elasticsearch,所以需要依赖包版本都一致。
方法:因此将es依赖包版本都降低,尽可能的新,同时TransportClient类不过时。
最终版本定为6.8.15,
org.elasticsearch elasticsearch6.8.15 org.elasticsearch.client elasticsearch-rest-high-level-client6.8.15
然后进行es获取索引数据量大小,
@Override public List报错:NoNodeAvailableException[None of the configured nodes are available。 看了网上的回答试了下都不大对,syncStorage(DatabasePO databasePO) { List storagePOList = new ArrayList<>(); ConnectionPO connectionPO = connectionDao.selectById(databasePO.getConnectionId()); RestHighLevelClient restHighLevelClient = init(databasePO, new ArrayList<>()); try { //连接数据库 Settings settings = Settings.builder().put("cluster.name", "elasticsearch") .put("client.transport.sniff", true) .build(); TransportClient client = new PreBuiltTransportClient(settings); TransportAddress address = new TransportAddress(InetAddress.getByName(connectionPO.getIp()), connectionPO.getPort()); client.addTransportAddress(address); //获取所有表 GetIndexRequest request = new GetIndexRequest("*"); GetIndexResponse response = restHighLevelClient.indices().get(request, RequestOptions.DEFAULT); // 获取所有的索引 String[] indices = response.getIndices(); for (String index : indices) { StoragePO storagePO = storageService.genarateStorage(databasePO, index); IndicesStatsResponse indicesStatsResponse = client.admin().indices().prepareStats(index).all().execute().actionGet(); CommonStats total = indicesStatsResponse.getTotal(); storagePO.setCapacity((int) (total.getStore().getSizeInBytes() / 2.0)); storagePOList.add(storagePO); } } catch (Exception e) { e.printStackTrace(); log.error("同步存在错误:" + e.getMessage()); } return storagePOList; }
原因真正的ES连接端口为9200(elasticsearch-rest-high-level-client连接就用9200端口),
但是elasticsearch所使用的端口就是9300,改完之后就可以用了。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)