Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/solr/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何使用Java在Solr中获取索引大小_Java_Solr - Fatal编程技术网

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

如何使用Java在Solr中获取索引大小,java,solr,Java,Solr,我需要使用Java获得ApacheSolr中索引的总大小。下面的代码获取文档的总数,但我正在查找大小。通过使用ReplicationHandler,我想我可以得到这里有人在这个链接上告诉我的索引大小。。但是我没有得到索引大小 BufferedWriter out1 = null; FileWriter fstream1 = new FileWriter("src/test/resources/solr-document-id-desc.txt"); out1 =

我需要使用Java获得ApacheSolr中索引的总大小。下面的代码获取文档的总数,但我正在查找大小。通过使用ReplicationHandler,我想我可以得到这里有人在这个链接上告诉我的索引大小。。但是我没有得到索引大小

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

indexsize可用于中的统计信息

org.apache.solr.handler.ReplicationHandler
代码

公共名称列表getStatistics(){ NamedList=super.getStatistics(); if(core!=null){ add(“indexSize”,NumberUtils.readableSize(getIndexSize()); } } 您可以使用URL
http://localhost:8983/solr/replication?command=details
,返回索引大小

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

26.13 KB
.....

不确定它是否与ReplicationHandler的实例化一起工作,因为它需要核心和索引的引用。

您可以使用数据目录中的命令

  - du -kx

如中所述,您可以使用以查看内存消耗情况。我认为您可以在代码中使用。享受solr

我的建议是让你的问题更清楚:)你已经给出了代码,但没有说你正在尝试做什么,或者它实际上做了什么,或者你一直遇到的任何问题。请阅读@JonSkeet,我已经更新了问题。现在让我知道它是否有意义…不是真的-你说你已经得到了索引大小,但是你“没有得到”它。。。那么会发生什么呢?我已经得到了Solr中的文档数量。。我需要索引大小。。!!“通过使用ReplicationHandler,我想我可以得到这个链接上有人告诉我的索引大小”-结果如何?我如何在代码中使用它。我想我已经在上面的代码中尝试过这样做了。试试statistics.get(“indexSize”);我已经更新了代码,我不会因此得到任何东西。。!!OP正在寻求用Java实现这一点的方法。