3

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.. 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.

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")); 
kellyfj
  • 6,586
  • 12
  • 45
  • 66
arsenal
  • 23,366
  • 85
  • 225
  • 331
  • My suggestion is that you make your question clearer :) You've presented code, but not said what you're *trying* to do or what it *actually* does, or any problems you've been having. Please read http://tinyurl.com/so-hints – Jon Skeet Oct 28 '11 at 19:44
  • @JonSkeet, I have updated the questions. let me know if it makes sense now.. – arsenal Oct 28 '11 at 19:50
  • Not really - you say you *have* got the index size, but that you're "not getting" it... so what happens? – Jon Skeet Oct 28 '11 at 19:59
  • I have got the number of documents in the Solr.. I need the index size..!! – arsenal Oct 28 '11 at 20:05
  • "And with the use of ReplicationHandler I was thinking that I can get the index size as told by someone here on this link" - and what was the result? – Jon Skeet Oct 28 '11 at 20:17
  • I am not getting anything. I just want to make sure what I did is right or wrong? How does ReplicationHandler is getting to know about which solr server we are talking about. – arsenal Oct 28 '11 at 20:48

3 Answers3

12

The indexsize is available with the statistics in 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.

<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.

cheffe
  • 9,345
  • 2
  • 46
  • 57
Jayendra
  • 52,349
  • 4
  • 80
  • 90
0

You can use the command in the data directory

  - du -kx
Brian Webster
  • 30,033
  • 48
  • 152
  • 225
ankit
  • 9
  • 1
0

as said in this post you can use MAT tool in order to see the memory consumption. I think that you could use in your code. Enjoy solr!

Community
  • 1
  • 1
jeorfevre
  • 2,286
  • 1
  • 17
  • 27