How to use java to get the index size in Solr
•
Java
I need to use java to get the total size of the index in Apache Solr The following code gets the total number of documents, but I'm looking for the size And by using replication handler, I think I can get the index size told on this link http://lucene.472066.n3.nabble.com/cheking-the-size-of-the-index-using-solrj-API-s-td692686.html But I didn't get 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"));
Solution
Indexsize can be used for 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>
It is uncertain whether it is suitable for instantiation of replicationhandler because it requires references to the core and index
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
二维码