13

I'm a newbie to solr and tying my hands at solr. Can some one here please explain how to specify multiple facet fields for a given search.

I'm using the Solr Admin UI/ query ink and it allows me to specify only one field. I would however like to facet on multiple fields like region industry stock-exchange etc on my company search.

I have gone through the solr wiki and relevant doc links like the one below http://docs.lucidworks.com/display/solr/Query+Screen

but none of them seem to explain how to specify multiple fields. I want to build something like the usual Amazon/Walmart etc search ui that provides multiple facets and counts when trying to search for a product on my planned cmpany search page.

Chetya
  • 1,267
  • 1
  • 17
  • 31
  • Got to this question googling for multiple nested facets, for anyone else who is looking for that (like total positive, negative and neutral comments by month) here are some links: http://yonik.com/solr-subfacets/ – HMR Sep 01 '15 at 01:38
  • Is the same possible through Solr panel(UI) ? – Nikhil Sahu Oct 16 '15 at 11:27

5 Answers5

17

You can query multiple facet fields. Just write with the syntax:

.../select?q=&facet=true&facet.field=<field1>&facet.field=<field2>
Mikael Engver
  • 4,634
  • 4
  • 46
  • 53
  • 3
    Looks like you got this. But to be clear.. since I was confused. You use the "Raw Query Parameters" field for this. – Ben Scheib Nov 04 '15 at 21:46
  • This does not seem to work as of version 7.0.0. SolrException, undefined field: "field1,field2" – McGarnagle May 26 '18 at 00:06
  • 1
    This works just fine in recent Solr, `` and `` are placeholders--you're meant to replace those values with the field names in your data – duhaime Nov 17 '20 at 20:51
2

When you execute the search in the Solr Query UI, it will show the actual url that is being sent to Solr above the results pane. Click on that url and it will open a new window in your browser to that url. From there you can add additional parameters to the url to get facteing on multiple fields, by adding additional &facet.field=<your field> entries.

Please see the Solr Faceting Parameters reference for more details and other options.

Paige Cook
  • 22,415
  • 3
  • 57
  • 68
2

You are looking for json.facet

It's available from solr 5(some advanced features are available from solr 6). Basically that means you can insert your facet search parameters via json to the url.

It looks like this(live example):

&facet=true&json.facet={"filed1":{"type":"terms","field":"filed1","limit":2000},"filed2":{"type":"terms","field":"filed2","limit":2000}}

There is also a shorter version:

&facet=true&json.facet={"field1":{"terms":"field1"},"field2":{"terms":"field2"}}

You can find more information here

Stas Sorokin
  • 3,029
  • 26
  • 18
0

The Solr Admin UI allows you to specify multiple facets fields i.e. a csv of fields in the facet.field parameter. You need to check the facet checkbox and then you will get more options.

If you are querying Solr using a link then the link should look like - facet=true&facet.field=field1&facet.field=field2.

Mikael Engver
  • 4,634
  • 4
  • 46
  • 53
JHS
  • 7,761
  • 2
  • 29
  • 53
  • 4
    Maybe that worked in 2013, but in a recent version, 8.2, it only works if you specify it in the URL, and not in the edit field provided by the admin panel. The edit field in the admin panel only works with one field. Putting two fields: FieldA, FieldB in CSV format creates a single field facet.field="FieldA, FieldB" in the generated URL which is incorrect. However, if you edit the query it produces to separate them as facet.field=FieldA&facet.field=FieldB, then of course it works. But the requester wanted to use the Admin UI directly, and your answer suggests that they can. – nrshapiro Apr 30 '20 at 21:36