redeemed
redeemed

Reputation: 511

Solr - Querying on nested child documents

I have a requirement where in a parent document has two child documents . For example , the doc which is indexed looks like this ,

{
"id":123,
"name":"nithin",
"_childDocuments_":[
{
"id":"22"
"place":"blr",
"parent_id":123,
"street":"inagar"
},
{
"id":"23"
"place":"tvm",
"parent_id":123,
"street":"bakery"
}
]
}

Here the name - nithin has two child documents with distinct place and street . My requirement is to query for all parents with a specific place and/or street . Lets say blr and bakery. If i fire a query saying (blr and bakery) it would not return any results . I cant use blr or bakery because i want a parent document for which the child docs should have blr and bakery . How do i achieve this ?

Upvotes: 0

Views: 2293

Answers (1)

Pavel Vasilev
Pavel Vasilev

Reputation: 1042

I think the best way to achieve your goal is through Block Join Parser capabilities.

What you need change a little bit - is to introduce some marker for parent documents. In Solr glossary it will be needed for "parent filter". So assuming each parent document will have content_type:parentDocument (just for sake of example) you'll be able to find all your parent documents with BJQ (block-join query) like:

{!parent which="content_type:parentDocument"}(+place:blr +street:bakery)

Please bear in mind you need to index your parent-children documents together (in the same block) as described on Solr wiki (but as I see you already doing so, I guess it should be good to go).

Upvotes: 1

Related Questions