gpt4 book ai didi

java - 如何使用 Java 在 Solr 中获取索引大小

转载 作者:塔克拉玛干 更新时间:2023-11-01 21:35:38 24 4
gpt4 key购买 nike

我需要使用 Java 在 Apache Solr 中获取索引的总大小。以下代码获取文档总数,但我正在寻找大小。通过使用 ReplicationHandler,我认为我可以获得此链接上有人告诉我的索引大小。http://lucene.472066.n3.nabble.com/cheking-the-size-of-the-index-using-solrj-API-s-td692686.html但我没有得到索引大小。

BufferedWriter out1 = null;
FileWriter fstream1 = new FileWriter("src/test/resources/solr-document-id-desc.txt");
out1 = new BufferedWriter(fstream1);
ApplicationContext context = null;
context = new ClassPathXmlApplicationContext("application-context.xml");
CommonsHttpSolrServer solrServer = (CommonsHttpSolrServer) context.getBean("solrServer");
SolrQuery solrQuery = new SolrQuery().setQuery("*:*");

QueryResponse rsp = solrServer.query(solrQuery);

//I am trying to use replicationhandler but I am not able to get the index size using statistics. Is there any way to get the index size..?
ReplicationHandler handler2 = new ReplicationHandler();
System.out.println( handler2.getDescription());

NamedList statistics = handler2.getStatistics();
System.out.println("Statistics "+ statistics);
System.out.println(rsp.getResults().getNumFound());

Iterator<SolrDocument> iter = rsp.getResults().iterator();

while (iter.hasNext()) {
SolrDocument resultDoc = iter.next();
System.out.println(resultDoc.getFieldNames());
String id = (String) resultDoc.getFieldValue("numFound");
String description = (String) resultDoc.getFieldValue("description");
System.out.println(id+"~~"+description);
out1.write(id+"~~"+description);
out1.newLine();
}
out1.close();

Any suggestions will be appreciated..

更新代码:-

ReplicationHandler handler2 = new ReplicationHandler();
System.out.println( handler2.getDescription());
NamedList statistics = handler2.getStatistics();
System.out.println("Statistics "+ statistics.get("indexSize"));

最佳答案

indexsize 在ReplicationHandler 中有统计数据。

org.apache.solr.handler.ReplicationHandler

代码

  public NamedList getStatistics() {
NamedList list = super.getStatistics();
if (core != null) {
list.add("indexSize", NumberUtils.readableSize(getIndexSize()));
}
}

您可以使用返回索引大小的 URL http://localhost:8983/solr/replication?command=details

<lst name="details">
<str name="indexSize">26.13 KB</str>
.....
</lst>

不确定它是否适用于 ReplicationHandler 的实例化,因为它需要核心和索引的引用。

关于java - 如何使用 Java 在 Solr 中获取索引大小,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7934000/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com