3

I have a two or more collection in mongodb that are replicated to solr indexes using mongo-solr connectors. For the sake of explaining my problem I am facing lets take the traditional example of employee & department example (I know it's Document oriented DB & I can embed department to employee document, but please allow me to explain my question with this trivial example):

Employee document:

{
   "_id": ObjectId(..),
   "firstName": "John",
   "lastName": "David",
   "departMent": ObjectId(..) - a DBRef for department document
}

Department document:

{
  "_id": ObjectId(..),
  "departmentName": "Marketing"
}

Let's say that above two documents are linked in employee document using the department's object id ref. Now mongo-solr connector replicated these structures as it is and let's assume all of the fields are indexed and stored.

Now here is my question ( & the problem):

If I search the solr index by employee firstName (or lastName), I should get back results in such a way that the solr search response should include the "departmentName" instead of the Department ObjectId reference and that this should happen over a single search request originating from a client.

How do I do this using Solr apis?

Thanks in advance.

Kick Buttowski
  • 6,709
  • 13
  • 37
  • 58
techcraver
  • 401
  • 3
  • 21

1 Answers1

1

The ideal solution of course (from Solr perspective) would be to store the data in Solr in the denormalized form. However, if that is not a viable option, you could take a look at the Join query Parser.

https://cwiki.apache.org/confluence/display/solr/Other+Parsers#OtherParsers-JoinQueryParser

You would be performing a query along the lines of (not tested):

q={!join from=department to=departmentName}lastName:David AND departmentName:Marketing
Fuu
  • 3,424
  • 4
  • 33
  • 49
  • Thanks Fuu. There is another stackoverflow thread I just found here:https://stackoverflow.com/questions/12665797/is-solr-4-0-capable-of-using-join-for-multiple-core You are also confirming it to use join query! Thanks a lot/ – techcraver May 07 '15 at 16:23