title: How to get the Index Size in Solr using Java
body: <p>I need to get total size of an index in Apache Solr using Java. 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.. <a href="http://lucene.472066.n3.nabble.com/cheking-the-size-of-the-index-using-solrj-API-s-td692686.html" rel="nofollow noreferrer">http://lucene.472066.n3.nabble.com/cheking-the-size-of-the-index-using-solrj-API-s-td692686.html</a> but I am not getting the index size.</p>
  
  <pre><code>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&lt;SolrDocument&gt; 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..
  </code></pre>
  
  <p><strong>Update Code:-</strong></p>
  
  <pre><code>ReplicationHandler handler2 = new ReplicationHandler();
  System.out.println( handler2.getDescription()); 
   NamedList statistics = handler2.getStatistics();
   System.out.println("Statistics   "+ statistics.get("indexSize")); 
  </code></pre>