There is 2 ways to achieve that :
Using
fl
parameter you can set a field list to return : set an empty string, or set a field name that does not exist in your index so that the request doesn't fallback to the default field list. It should return a list of empty documents :SolrQuery query = new SolrQuery(); query.setQuery("something to search"); query.set("fl", "unknown_field"); SolrDocumentList out = server.query(query).getResults();
using
rows
parameter (should be preferred), ask solr to return 0 document :query.setRows(0); server.query(query).getResults();
In both cases getNumFound()
method should return the number of matched documents.