Reputation: 86
I was going through Yonik's blog. I am using solr 5.3.0 and I have a scenario which I am trying to solve. Any help will be appreciated.
Generalizing Yonik's example:
Old Document:
{
product_name : "Awesome T-Shirt",
category : "Clothing",
color : [ "Red", "Blue"],
size : [ "L", "M", "XL" ]
}
Parent:
{
product_name : "Awesome T-Shirt",
category : "Clothing",
}
Nested Children:
{
color : "Red",
size : "L",
quantity: 2
}
{
color : "Blue",
size : "M",
quantity: 3
}
{
color : "Blue",
size : "L",
quantity: 0
}
{
color : "Red",
size : "L",
quantity: 0
}
{
color : "Red",
size : "XL",
quantity: 1
}
Counting some scenarios: 1) If I put filter for color:Red and size:L I get the children documents only. Is that possible to get the parent fields on response (Since I have multiple products with color:Red and size:L).
2) If I search for color:Red and quantity greater than 0, I get multiple documents while this search is just to check if item in red color is available. Though group by is a work around, is there any other way.
Upvotes: 1
Views: 3437
Reputation: 1573
If you want to get parent documents
with child documents
I'd do this:
/select?q=id:<parent id>
&fq=type:<parent type>
&fl=*,[child parentFilter="type:<parent type>" limit=10]
it will return a structure like this:
{
"type":"<parent type>",
....
"_childDocuments_":[{
<doc>..</doc>
...
<doc>..</doc>
}]
}
child document count is limited with limit=10
you can change that of course but default is 10 :)
Upvotes: 4