Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 291
Oussama Jilal Avatar asked Feb 23 '26 01:02

Oussama Jilal


1 Answers

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).

like image 184
Oussama Jilal Avatar answered Feb 27 '26 03:02

Oussama Jilal