问题
I'm using SOLR 4.6 with Parent and Child documents. I know that I can use 'join' or 'block join' to find documents of specific type (Child or Parent),
But, can I get Parent doc fields and Child doc fields in the same response?
For Example: If I have Person with firstName=Bob and LastName=Marley And Child doc Address with City=NY
I would like to get firstName=Bob, LastName=Marley and City=NY in the result document.
回答1:
Try Index time Block join with parent child relations and use the expand component (Solr 4.8) in the query. For more details check Joel's post @ http://heliosearch.org/expand-block-join/
回答2:
According Solr Documentation it is not possible. http://wiki.apache.org/solr/Join
"For people who are used to SQL, it's important to note that Joins in Solr are not really equivalent to SQL Joins because no information about the table being joined "from" is carried forward into the final result. A more appropriate SQL analogy would be an "inner query".
This Solr request...
/solr/collection1/select ? fl=xxx,yyy & q={!join from=inner_id to=outer_id}zzz:vvv Is comparable to this SQL statement...
SELECT xxx, yyy FROM collection1 WHERE outer_id IN (SELECT inner_id FROM collection1 where zzz = "vvv")
回答3:
Actually this is still impossible BUT. There is a patch that can be found here - SOLR-5285
回答4:
Child documents can be retrieved with the help of expand attribute as explained in expand block join. If we add
expand=true&expand.q=*:*&expand.field=_root_
to the query. We should be able to get all child documents in "extended" attribute.
来源:https://stackoverflow.com/questions/20826325/solr-can-i-get-parent-fields-and-child-fields-in-the-same-result