I'm working with Solr and facing a challenge related to sorting parent documents based on values from associated child documents.
Scenario:
- I have two types of documents:
products
(as parent documents) andreviews
(as child documents). (They are located at different cores) - Each
product
has a uniqueproduct_id
. - Each
review
references a product via aproduct_id
field. - I want to retrieve and sort products based on some aggregate value from their reviews (e.g., average review score).
From my understanding, Solr doesn't support a direct method to sort parent documents by aggregated values of child documents, like a traditional SQL JOIN with GROUP BY and ORDER BY would.
Question:
- What is the recommended approach to achieve this sorting in Solr?
- Are there any workarounds or third-party extensions that could assist in this?
I've considered denormalizing the data and incorporating the average review score directly into the product document at index time, but I wonder if there's a more dynamic approach that doesn't require re-indexing products when new reviews are added.
Any guidance would be greatly appreciated!
Just FYI I use {!join from=product_id to=id}*:*
syntax to receive the result set.