Solr/Solrj: How can I determine the total number of documents in an index?
Pasting the whole curl
:
curl -s --negotiate -u: 'hostname:8983/solr/my_collection/query?q=*:*&rows=0' | jq '.response | .numFound'
1868000278
Your answer of sending the query *:*
is probably the best, most general solution. Especially if you are using SolrCloud. However, there is an alternate solution, the Solr Core Admin API
Here's what I'm using. Is this canonical? Is there a better way?
SolrQuery q = new SolrQuery("*:*");
q.setRows(0); // don't actually request any data
return server.query(q).getResults().getNumFound();