Search code examples
solrfieldgrouping

Solr Grouping empty field


Edit

I'm sorry if I did not explain well my need. I'll try to give a better explanation.

What I have : Millions of documents that have a field X , another field Y and another field Z which is not required (So it can be empty in some documents and not in others).

What I want to do : Search for docs that have the field X equals something and group them by field Z (so that only 1 document is returned for every field Z value), BUT I want documents who have field Z as empty to be included in the results (all of them), and sort the results by field Y (so I can't separate the request into two requests).

I hope that this is clearer.


Solution

  • This is the best answer I could find for my issue (from the solr mailing list users) :

    The idea is to use a copy field of the field Z, and, when indexing data, if the field Z is empty, generate a unique value in the copy field. And when grouping, use the copy field instead of field Z. (if the field Z is only needed for grouping, he can be used alone without the copy field).