如何在solr中获取索引大小 [英] how to get the Index Size in solr

查看:216
本文介绍了如何在solr中获取索引大小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要在Java中获取Apache Solr中的总文档的索引大小。此代码获取numFound意味着Apache Solr中的文档总数。通过使用ReplicationHandler,我认为我可以通过此链接上的某个人获得索引大小。 http://lucene.472066.n3.nabble.com/cheking-the-size-of-the-index - 使用 - solrj-API-S-td692686.html 。但我没有得到索引大小。

I need to get the Index Size of the total documents in Apache Solr in Java. And this code is getting the numFound means total number of documents in Apache Solr. 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..

更新代码: -

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


推荐答案

indexsize与 ReplicationHandler

The indexsize is available with the statistics in ReplicationHandler

org.apache.solr.handler.ReplicationHandler

代码

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

您可以使用网址 http:// localhost:8983 / solr / replication?command = details ,返回索引大小。

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>

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

Not sure if it works with the instantiation of ReplicationHandler, as it would need the reference of the core and the index.

这篇关于如何在solr中获取索引大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆