加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > Java > 正文

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

发布时间:2020-12-15 04:56:04 所属栏目:Java 来源:网络整理
导读:我需要使用 Java获取Apache Solr中索引的总大小.以下代码获取文档总数,但我正在寻找大小.并且通过使用ReplicationHandler,我认为我可以获得此链接上有人告诉的索引大小. http://lucene.472066.n3.nabble.com/cheking-the-size-of-the-index-using-solrj-API-
我需要使用 Java获取Apache Solr中索引的总大小.以下代码获取文档总数,但我正在寻找大小.并且通过使用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..

更新代码: –

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

解决方法

indexsize可用于 ReplicationHandler中的统计信息

org.apache.solr.handler.ReplicationHandler

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

您可以使用URL http:// localhost:8983 / solr / replication?command = details,它返回索引大小.

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

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

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读