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.
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.
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();
wget http://hostname:8983/solr/collection_name_here/query?q=*:*
also does the trick :)` (and stores the result in a file called query?q=*:*
) –
Sclaff http://hostname:8983/solr/collection_name_here/query?q=*:*&rows=0
–
Communalism 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
Pasting the whole curl
:
curl -s --negotiate -u: 'hostname:8983/solr/my_collection/query?q=*:*&rows=0' | jq '.response | .numFound'
1868000278
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 />";
Depending how you are using it, notice the format options available. For my case XML is ideal.
http://localhost:8983/solr/drupal/select?q=*%3A*&rows=0&wt=xml
© 2022 - 2024 — McMap. All rights reserved.
http://hostname:8983/solr/collection_name_here/query?debug=query&q=*:*
andnumFound
contains the count. – Rajiv