Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to exclude fields in a SOLR query

I have a SOLR query which should fetch all the fields I store, except one field.
Say I have 20 fields, do I need to hard code the 19 fields I want to fetch in the
&fl=[f],[f],[f],....[f]'
Or is there a way to do something similar to
&fl=*,![f]'

[f] stands for a field name.

like image 947
Itay Moav -Malimovka Avatar asked Apr 19 '13 16:04

Itay Moav -Malimovka


2 Answers

Another option would be using the Document transformer ValueAugmenterFactory to replace the actual value returned of the field by an empty string.

This should work if your requirement is simply to avoid returning the content of that field.

Below is a example replacing the content of the title field:

&fl=*,title:[value v=""]
like image 108
Wellington Avatar answered Sep 30 '22 14:09

Wellington


Unfortunately the ability to remove a field name via the query string is still an outstanding improvement request. Please see SOLR-3191 for more details.

Until this improvement is implemented, you will need to specify all 19 fields in the fl parameter. However, you could update your default /select requestHandler to define the 19 fields that you want to return as a default setting that would be applied to all queries unless it was overridden in the query string.

Here is a modified version of the default /select requestHandler from the example solrconfig.xml:

  <requestHandler name="/select" class="solr.SearchHandler">
    <!-- default values for query parameters can be specified, these
     will be overridden by parameters in the request
     -->
    <lst name="defaults">
      <str name="echoParams">explicit</str>
      <int name="rows">10</int>
      <str name="df">text</str>
      <!-- Only showing 3 fields for this example -->
      <str name="fl">field1,field2,field3</str>
    </lst>
  </requestHandler>

For more details about these default settings and requestHandler configuration, please refer to RequestHandlers and SearchComponents in SolrConfig.

like image 20
Paige Cook Avatar answered Sep 30 '22 13:09

Paige Cook