Solr - how to get all faceted field's values?

mihutz picture mihutz · May 5, 2016 · Viewed 7.7k times · Source

I have a huge solr index with ~1.500.000 items and I want to get all distinct Brands.

I tried this solr query: select/?q=*&rows=0&facet=on&facet.field=brand , but not all brands are displayed (just some of them).

Solr response:

    <response>
    <lst name="responseHeader">
        <int name="status">0</int>
        <int name="QTime">39</int>
        <lst name="params">
            <str name="facet">on</str>
            <str name="facet.mincount">0</str>
            <str name="q">*</str>
            <str name="facet.field">brand</str>
            <str name="rows">0</str>
        </lst>
    </lst>
    <result name="response" numFound="1520444" start="0"/>
    <lst name="facet_counts">
        <lst name="facet_queries"/>
        <lst name="facet_fields">
            <lst name="brand">
                <int name=" ">51099</int>
                <int name="Blancheporte">11269</int>
                <int name="Ama Fashion">8254</int>
                <int name="Heine">7026</int>
                <int name="Kolok">6874</int>
                <int name="Knecht">6836</int>
                <int name="JoyJoy">6139</int>
                <int name="MyDressing">5418</int>
                <int name="Widmann Italia">5310</int>
                <int name="modlet">4476</int>
                <int name="Mann-Filter">4243</int>
                <int name="Daniel Klein">4033</int>
                <int name="LEGO">4002</int>
                <int name="Casio">3887</int>
                <int name="Canon">3706</int>
                <int name="Generic">3641</int>
                <int name="HP">3608</int>
                <int name="PUMA">3593</int>
                <int name="Nespecificat">3552</int>
                <int name="YATO">3421</int>
                <int name="Philips">3397</int>
                <int name="Polirom">3320</int>
                <int name="LE COQ SPORTIF">3154</int>
                <int name="Bullyland">3056</int>
                <int name="PIATRAONLINE.RO">2863</int>
                <int name="Ravensburger">2775</int>
                <int name="Samsung">2612</int>
                <int name="Zambirici">2612</int>
                <int name="ASUS">2579</int>
                <int name="Humanitas">2536</int>
                <int name="MyKids">2485</int>
                <int name="""">2484</int>
                <int name="QQ">2467</int>
                <int name="Chipolino">2441</int>
                <int name="VOREL">2386</int>
                <int name="Disney">2367</int>
                <int name="Bosch">2287</int>
                <int name="Kingston">2259</int>
                <int name="Litera">2255</int>
                <int name="Dell">2122</int>
                <int name="Corsair">2116</int>
                <int name="Lenovo">2057</int>
                <int name="RAO">2054</int>
                <int name="Mango">2049</int>
                <int name=""">2043</int>
                <int name="Playmobil">2003</int>
                <int name="Melissa & Doug">1995</int>
                <int name="BOOKCITY">1985</int>
                <int name="Epson">1980</int>
                <int name="SAMSUNG">1961</int>
                <int name="Meli Melo - Paris">1932</int>
                <int name="Moje Bambino">1917</int>
                <int name="Mattel">1906</int>
                <int name="Q-Hausmarke">1875</int>
                <int name="Mahle&nbsp;Original">1856</int>
                <int name="Purflux">1844</int>
                <int name="Orient">1763</int>
                <int name="Triumph">1739</int>
                <int name="THEICONIC">1731</int>
                <int name="Michelin ">1721</int>
                <int name="Vero Moda">1694</int>
                <int name="Pirelli ">1681</int>
                <int name="Marko">1679</int>
                <int name="Lorelli">1674</int>
                <int name="Peg Perego">1646</int>
                <int name="Hengst&nbsp;Filter">1642</int>
                <int name="Trendzilla">1612</int>
                <int name="Hasbro">1611</int>
                <int name="Brother">1552</int>
                <int name="Baby Mix">1540</int>
                <int name="Adidas">1526</int>
                <int name="Brevi">1517</int>
                <int name="oteros">1511</int>
                <int name="Continental ">1500</int>
                <int name="Microsoft">1492</int>
                <int name="PEPE JEANS">1480</int>
                <int name="Bertoni-Lorelli">1465</int>
                <int name="Sony">1464</int>
                <int name="R essentiel">1452</int>
                <int name="Trespass">1420</int>
                <int name="Hauck">1418</int>
                <int name="Clementoni">1409</int>
                <int name="Revell">1390</int>
                <int name="Miniland">1388</int>
                <int name="Floria">1366</int>
                <int name="Sense">1338</int>
                <int name="Lexmark">1332</int>
                <int name="Altii">1317</int>
                <int name="Salomon ">1296</int>
                <int name="Hewlett Packard">1295</int>
                <int name="SAMSUNG ">1290</int>
                <int name="D-Mail">1283</int>
                <int name="Make-up Studio PROFESSIONAL">1253</int>
                <int name="Panasonic">1251</int>
                <int name="Zara">1243</int>
                <int name="Gigabyte">1237</int>
                <int name="Trei">1233</int>
                <int name="Tommy Hilfiger">1227</int>
                <int name="Divisima">1219</int>
                <int name="Bright Starts">1214</int>
            </lst>
        </lst>
        <lst name="facet_dates"/>
        <lst name="facet_ranges"/>
        <lst name="facet_intervals"/>
        <lst name="facet_heatmaps"/>
    </lst>
</response>

I think there is a limit.. or the way I am trying to get them is wrong.

Do you know how I can get all distinct values from one field, using solr?

Thanks!

Answer

TMBT picture TMBT · May 5, 2016

If you want to get all the brands (assuming there are more than 100) and have them listed in the facet_fields, you'll need to set facet.limit to -1. In SolrJ, that would look something like this: query.setFacetLimit(-1);.

From the docs:

This param indicates the maximum number of constraint counts that should be returned for the facet fields. A negative value means unlimited.

The default value is 100.

This parameter can be specified on a per field basis to indicate a separate limit for certain fields.

If your issue is no documents are being returned, the rows parameter needs to be set to something other than zero.