0

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 ?

redeemed
  • 471
  • 7
  • 22
  • Answer is found at http://stackoverflow.com/questions/35003195/solr-block-join-parent-query-with-many-children-constraints – redeemed Nov 19 '16 at 16:57

1 Answers1

1

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).

Pavel Vasilev
  • 1,002
  • 1
  • 10
  • 11
  • This would not work as this basically queries for a single child document which has place as blr or street as bakery and corresponding parents are returned . What i need is parents for which both place and street is blr or bakery , which means blr can appear in one child document and bakery in another child document . To make it short , i need a parent only if he has two sons . For ex: if i search for Abel AND Cain i should get only Adam , eventhough Adam1 and Adam2 may have Abel or Cain and not both – redeemed Nov 09 '16 at 04:43
  • Sorry, missed that part. I bet Solr doesn't have out-of-the-box plugin. My suggestion is trying to make fake child and put all field values there. Seems ugly, I know but it works. – Pavel Vasilev Nov 09 '16 at 13:21
  • Yeah basically having only one child document per parent with the values for each field clubbed together as an array . That would solve this , but that would get rid of the correlation between fields , Was thinking of something like this , q = (Abel OR Cain)&facet=true&facet.field=parent_id&facet.mincount=2 . This would give me all the parent_ids which has Abel and Cain as children . And programatically i can count the number of elements in the facet array returned . Does it make sense ? – redeemed Nov 09 '16 at 16:18