0

I want to have in Solr children documents. I'm using SolrJ to index the documents and I use the method addChildDocument.

In my structure of data I would have a parent object like a parent and children objects and I thought in the begining about using multivalue fields, the problem it's that if I use multivalue I lose that the value X belongs to childX and the value Y belongs to childY.

When I have used the method addChildDocument and query Solr, it seems that they aren't really linked, Instance of there are complete isolate documents.

I want to store in the same collection for historical reasons "books" and "writers", they would be liks this:

{...,
bookName : aaaa,
pages : 222,
...
authors: [
 { author : bbbb,
   age : 33,
   ...
 },
 { author : ....
 }
]
}

I know that it's not possible to do this in Solr, but I don't know how to model this structure in Solr or I should do it in another way.

Guille
  • 2,248
  • 3
  • 24
  • 42
  • maybe this could help: https://cwiki.apache.org/confluence/display/solr/Uploading+Data+with+Index+Handlers#UploadingDatawithIndexHandlers-NestedChildDocuments – Zac Jul 27 '15 at 09:27
  • 1
    possible duplicate of [Solr documents with child elements?](http://stackoverflow.com/questions/5584857/solr-documents-with-child-elements) – Zac Jul 27 '15 at 09:30

1 Answers1

1

The way you are doing with addChildDocument is correct approach to add child documents. At the end, solr maintains the relation and you need to have a field which can identify difference between parent and child. Can you elaborate how you identified "it seems that they aren't really linked, Instance of there are complete isolate documents".

Your indexing part is correct. Once indexed, you should (1+n) documents(parent + n children). The way you search is through block join query. This will help you to query for parent for a field value in child, and vice versa.

Ramzy
  • 6,948
  • 6
  • 18
  • 30
  • Thanks, I was checking how they do queries. I'm not sure if it's going to work to me because I'm using Solr + Hue and I can't define the queries. Hue just takes data from Solr and does some graphs automatically. So, I can't tell it,, this document is a child and its content_type is XXXXX – Guille Jul 28 '15 at 08:24