Reputation: 2320
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.
Upvotes: 0
Views: 1106
Reputation: 7138
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.
Upvotes: 1