The Solr Javadoc has an example:

http://lucene.apache.org/solr/4_3_0/solr-core/org/apache/solr/update/processor/CountFieldValuesUpdateProcessorFactory.html

I have a more complete example (plus others) in the book:

Example - Store a count of the values of a named multivalued field in another field

 <updateRequestProcessorChain name="count-features">
   <processor class="solr.CloneFieldUpdateProcessorFactory">
     <str name="source">features</str>
     <str name="dest">features_count_i</str>
   </processor>
   <processor class="solr.CountFieldValuesUpdateProcessorFactory">
     <str name="fieldName">features_count_i</str>
   </processor>
   <processor class="solr.DefaultValueUpdateProcessorFactory">
     <str name="fieldName">features_count_i</str>
     <int name="value">0</int>
   </processor>
   <processor class="solr.LogUpdateProcessorFactory" />
   <processor class="solr.RunUpdateProcessorFactory" />
 </updateRequestProcessorChain>

Note the use of the Default Value Update processor to assure that the "features_count_i" has a numeric value of "0" if
there were no input values for the "features" field.

Index content:

curl "http://localhost:8983/solr/update?commit=true&update.chain=count-features"; \
 -H 'Content-type:application/json' -d '
 [{"id": "doc-1",
   "title_s": "Hello World",
   "features": ["Fast", "Cheap", "Flexible", "Reliable", "X"]}]'

Results:

 "id":"doc-1",
 "title_s":"Hello World",
 "features":["Fast",
   "Cheap",
   "Flexible",
   "Reliable",
   "X"],
 "features_count_i":5,

-- Jack Krupansky

-----Original Message----- From: Alexandre Rafalovitch
Sent: Tuesday, June 11, 2013 8:28 AM
To: [email protected]
Subject: Re: Documents with multiple values in a certain field

I believe the usual solution is to pre-calculate that by using
UpdateRequestProcessor (probably:
CountFieldValuesUpdateProcessorFactory ).

Regards,
  Alex.
Personal blog: http://blog.outerthoughts.com/
LinkedIn: http://www.linkedin.com/in/alexandrerafalovitch
- Time is the quality of nature that keeps events from happening all
at once. Lately, it doesn't seem to be working.  (Anonymous  - via GTD
book)


On Tue, Jun 11, 2013 at 5:43 AM, Silvio Hermann <[email protected]> wrote:
Hello,

is there a way to get all documents where a certain field has multiple
entries?

best,

Silvio

Reply via email to