I'm trying to use a SimpleQuery to get distinct result from my solr collection, but even after setting my StatsOption with calcDistinct true, I can't get the result I want.
BTW I'm using spring-data-solr-2.1.4.RELEASE.
SampleCode:
Field field = new SimpleField("fieldName");
StatsOptions statsOptions = new StatsOptions().addField(field).setCalcDistinct(true);
SimpleQuery query = new SimpleQuery("*:*").setStatsOptions(statsOptions);
StatsPage<MyClass> statsPage = solrTemplate.queryForStatsPage(query, MyClass.class);
FieldStatsResult statsResult = statsPage.getFieldStatsResult(field);
Collection<Object> distinctValues = statsResult.getDistinctValues();
Set<String> result = distinctValues.stream().map((i) -> i.toString()).collect(Collectors.toSet());
return result;
After trying the above code, all I get is the max, min, count, but no results for distinct totals or distinct values.

What am I doing wrong in this sample?
Looks like your
disctintValuescollection is also an implementation ofEmptyListwhich means that there are no values in the response.Check if your query returns any result, first.