Reputation: 2499
Related to question How to select distinct field values using Solr? but what I want is the counter.
I want to know how many distinct elements there is in a Solr field. I could get this number by using:
group.field=my_field&group.ngroups=true&group.limit=0
but doing grouping for this seems like an overkill
Is there another way ? Do I have to use JIRA SOLR-1814 ?
Upvotes: 1
Views: 5133
Reputation: 52779
If you are looking for unique values in the fields. You can facet on the field name with the field type string, which will return all the unique values for the field (and the counts which may or may not be relevant to you).
The following patch @ https://issues.apache.org/jira/browse/SOLR-2242 will help you to get the count directly. If you can't use the patch, you would probably need to get all the values for the facet field and count by yourself.
Upvotes: 1
Reputation: 36
SOLR 3.3 and newer already accept group facetting
So if you simply apply a facet.query it should return the number of rows for your query. But I don't know of any other way to count your groups if you want to make such a query. I doubt that is possible any other way.
Upvotes: 0