title: Solr: To get all records
body: <p>I am trying to upgrade my Solr 4.x version to 5.2.1 Solrcloud implementation. I had written following code to get all the results from Sorl query which works well in Solr single instance mode.</p>
  
  <pre><code>SolrQuery query = new SolrQuery();
  query.setQuery("*:*");
  query.addSort("agent_status", ORDER.desc);
  query.addFilterQuery("account_id:\"" + accountId + "\"");
  query.set("rows", Integer.MAX_VALUE);
  </code></pre>
  
  <p>But code will not work well in SolrCloud implemenation.It throws following exception.</p>
  
  <pre><code>2015-08-14 16:44:45,648 ERROR [solr.core.SolrCore] - [http-8080-8] : java.lang.NegativeArraySizeException
  at org.apache.lucene.util.PriorityQueue.&lt;init&gt;(PriorityQueue.java:58)
  at org.apache.lucene.util.PriorityQueue.&lt;init&gt;(PriorityQueue.java:39)
  at org.apache.solr.handler.component.ShardFieldSortedHitQueue.&lt;init&gt;(ShardDoc.java:113)
  at org.apache.solr.handler.component.QueryComponent.mergeIds(QueryComponent.java:972)
  at org.apache.solr.handler.component.QueryComponent.handleRegularResponses(QueryComponent.java:750)
  at org.apache.solr.handler.component.QueryComponent.handleResponses(QueryComponent.java:729)
  at org.apache.solr.handler.component.SearchHandler.handleRequestBody(SearchHandler.java:388)
  at org.apache.solr.handler.RequestHandlerBase.handleRequest(RequestHandlerBase.java:143)
  </code></pre>
  
  <p>I found that it is failing because of <code>query.set("rows", Integer.MAX_VALUE)</code> statement.People suggested me to use pagination.
  But, I can not afford doing pagination as there will be too many changes  at UI side.</p>
  
  <p>There is one more way where I can first query with some small number &amp; get total number of documents using <code>response.getResults().getNumFound()</code> method &amp; try setting that value to <code>setRows</code> method.But this approach will increase one more call to server.</p>
  
  <p>Is there any other way I can solve this problem?</p>