'Solr/Solrj: How can I determine the total number of documents in an index?
How can I determine the total number of documents in a Solr index using Solrj?
After hours of searching on my own, I actually have an answer (given below); I'm only posting this question so others can find the solution more easily.
Solution 1:[1]
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
Solution 2:[2]
Pasting the whole curl:
curl -s --negotiate -u: 'hostname:8983/solr/my_collection/query?q=*:*&rows=0' | jq '.response | .numFound'
1868000278
Solution 3:[3]
Here's what I use to get total docs using JSON/PHP hope this helps
// Get total number of documents in solr
$solrObj = file_get_contents("http://HOSTNAME:8983/solr/COLLECTION
NAME/select?q=*:*&rows=0&wt=json");
// var_dump(json_decode($solrObj));
$res_obj = json_decode($solrObj);
$numDocs = $res_obj->response->numFound;
echo "Total number docs found!: ".$numDocs."<br />";
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | mlissner |
| Solution 2 | michalrudko |
| Solution 3 | Tyler2P |
