In case anyone is interested, I solved my problem using the "grouping" feature:
*query* --> "filter" query (if any) *field* --> field that you want to count (in my case field "B") SolrQuery solrQuery = new SolrQuery(query); solrQuery.add("group", "true"); solrQuery.add("group.field", "B"); // Group by the field solrQuery.add("group.ngroups", "true"); solrQuery.setRows(0); And in the response *getNGroups()* will give you the total number of distinct values (total number of "B" distinct values) Cheers, Carlos. 2013/5/18 Carlos Bonilla <carlosbonill...@gmail.com> > Hi Mikhail, > yes the thing is that I need to take into account different queries and > that's why I can't use the Terms Component. > > Cheers. > > > 2013/5/17 Mikhail Khludnev <mkhlud...@griddynamics.com> > >> On Fri, May 17, 2013 at 12:47 PM, Carlos Bonilla >> <carlosbonill...@gmail.com>wrote: >> >> > We >> > only need to calculate how many different "B" values have more than 1 >> > document but it takes ages >> > >> >> Carlos, >> It's not clear whether you need to take results of a query into account or >> just gather statistics from index. if later you can just enumerate terms >> and watch into TermsEnum.docFreq() . Am I getting it right? >> >> >> -- >> Sincerely yours >> Mikhail Khludnev >> Principal Engineer, >> Grid Dynamics >> >> <http://www.griddynamics.com> >> <mkhlud...@griddynamics.com> >> > >