简体   繁体   English

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

[英]How to get the Index Size in Solr using Java

I need to get total size of an index in Apache Solr using Java. 我需要使用Java在Apache Solr中获取索引的总大小。 The following code gets the total number of documents but I am looking for the size. 以下代码获取文档总数,但是我正在寻找大小。 And with the use of ReplicationHandler I was thinking that I can get the index size as told by someone here on this link.. http://lucene.472066.n3.nabble.com/cheking-the-size-of-the-index-using-solrj-API-s-td692686.html but I am not getting the index size. 并通过使用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..

Update Code:- 更新代码:

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

The indexsize is available with the statistics in ReplicationHandler indexsize与ReplicationHandler中的统计信息一起提供

org.apache.solr.handler.ReplicationHandler

code

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

You can use the URL http://localhost:8983/solr/replication?command=details , which returns the index size. 您可以使用URL http://localhost:8983/solr/replication?command=details来返回索引大小。

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

Not sure if it works with the instantiation of ReplicationHandler, as it would need the reference of the core and the index. 不确定它是否可以与ReplicationHandler的实例一起使用,因为它将需要内核和索引的引用。

您可以在数据目录中使用该命令

  - du -kx

as said in this post you can use MAT tool in order to see the memory consumption. 在说这个帖子 ,你可以使用MAT工具才能看到内存的消耗。 I think that you could use in your code. 我认为您可以在代码中使用。 Enjoy solr! 享受solr!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM