如何使用Java获取Solr中的索引大小

ars*_*nal 3 java solr

我需要使用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..
Run Code Online (Sandbox Code Playgroud)

更新代码: -

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

Jay*_*dra 12

indexsize可与ReplicationHandler中的统计信息一起使用

org.apache.solr.handler.ReplicationHandler
Run Code Online (Sandbox Code Playgroud)

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

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

<lst name="details">
  <str name="indexSize">26.13 KB</str>
  .....
</lst>
Run Code Online (Sandbox Code Playgroud)

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