I would like to do the equivalent of this SQL but with Solr as my data store.
SELECT
DISTINCT txt
FROM
my_table;
What syntax would fo
Solr 5.1 and later has the new Facet Module that has integrated support for finding the number of unique values in a field. You can even find the number of unique values in a field for each bucket of a facet, and sort by that value to find the highest or lowest number of unique values.
Number of unique values in "myfield": json.facet={x:'unique(myfield)'}
Facet by "category" field, and for each category, show the number of unique values in "color":
json.facet={
cat_breakdown : { terms : { // group results by unique values of "category"
field : category,
facet : {
x : "unique(color)", // for each category, find the number of unique colors
y : "avg(price)" // for each category, find the average price
}
}}
}
This is in Solr 5.1 and later. More facet functions like "unique" are shown at http://yonik.com/solr-facet-functions/