如何使用 SolrJ 检查每个索引的不同分片的哪些 IP 地址已启动并在 Solr 服务器中运行

How to check which IP addresses of different shards for each index are up and functioning in a Solr server using SolrJ

仅给定 Solr 服务器的 HTTP URL,我必须检查服务器在碎片中存储数据的所有 IP 地址和端口,然后 return 任何已关闭的 IP 服务器并且无法正常工作。

我必须通过在 Eclipse 中编写 Java 代码来完成此操作。我找到了一个可以查询 Solr 数据库的 Java API SolrJ,但我不确定如何获取所有分片及其 IP 地址。任何一段代码或过程都会有很大帮助。

您可以在 SolrJ 中使用 Collections API 调用来请求集群状态,这也意味着活动节点等。

可以这样做:

final SolrClient client = getSolrClient();

final SolrRequest request = new CollectionAdminRequest.ClusterStatus();

final NamedList<Object> response = client.request(request);
final NamedList<Object> cluster = (NamedList<Object>) response.get("cluster");
final List<String> liveNodes = (List<String>) cluster.get("live_nodes");

print("Found " + liveNodes.size() + " live nodes");

有关它的更多信息 - https://lucene.apache.org/solr/guide/7_3/using-solrj.html#other-apis