You are viewing a plain text version of this content. The canonical link for it is here.
Posted to solr-user@lucene.apache.org by Naman Jain <na...@gmail.com> on 2020/02/27 09:07:22 UTC

Mix Index having child-free and nested documents

I have a solr core which has a mix of child-free and with-child documents,
sample xml:
<add>
<doc>
<field name="id">4</field>
<field name="title">Regular Shirt</field>
<field name="doc_type">Parent</field>
<field name="color">Black</field>
</doc>
<doc>
<field name="id">8</field>
<field name="title">Solid Rug</field>
<field name="doc_type">Parent</field>
<field name="pattern">Solid</field>
</doc>
<doc>
<field name="id">1</field>
<field name="title">Regular color Shirts</field>
<field name="doc_type">Parent</field>
<field name="items">
<doc>
<field name="id">2</field>
<field name="doc_type">Child</field>
<field name="pcs_color">Red</field>>
</doc>
<doc>
<field name="id">3</field>
<field name="doc_type">Child</field>
<field name="color">Blue</field>>
</doc>
</field>
</doc>
<doc>
<field name="id">5</field>
<field name="title">Rugs</field>
<field name="doc_type">Parent</field>
<field name="items">
<doc>
<field name="id">6</field>
<field name="doc_type">Child</field>
<field name="pattern">Abstract</field>
</doc>
<doc>
<field name="id">7</field>
<field name="doc_type">Child</field>
<field name="pattern">Printed</field>
</doc>
</field>
</doc>
</add>
Now i want to write a query which fetched all items [with child and without
child] with color:red, title having shirt
Here is my query:
/solr/test/select?q={!parent%20which=doc_type:Parent%20score=max}%20%20{!boost%20b=100.0%20}pcs_color:Red%20{!dismax%20qf=title%20v=%27Regular%27%20score=total}&fl=id,product_class_type,title,score,pcs_color&wt=json
<http://localhost:8983/solr/test/select?q={!parent%20which=doc_type:Parent%20score=max}%20%20{!boost%20b=100.0%20}pcs_color:Red%20{!dismax%20qf=title%20v=%27Regular%27%20score=total}&fl=id,product_class_type,title,score,pcs_color&wt=json>

Error:
"msg": "Child query must not match same docs with parent filter. Combine
them as must clauses (+) to find a problem doc. docId=4, class
org.apache.lucene.search.DisjunctionSumScorer",
I think docId 4 is matching with query but as this is a parent solr is
throwing error.

How to proceed here?

Re: Mix Index having child-free and nested documents

Posted by Naman Jain <na...@gmail.com>.
here is query
/solr/test/select?q={!parent%20which=doc_type:Parent%20score=max}%20%20{!boost%20b=100.0%20}color:Red%20{!dismax%20qf=title%20v=%27Regular%27%20score=total}&fl=id,product_class_type,title,score,color&wt=json
<http://localhost:8983/solr/test/select?q=%7B!parent%20which=doc_type:Parent%20score=max%7D%20%20%7B!boost%20b=100.0%20%7Dpcs_color:Red%20%7B!dismax%20qf=title%20v=%27Regular%27%20score=total%7D&fl=id,product_class_type,title,score,pcs_color&wt=json>

On Thu, Feb 27, 2020 at 2:37 PM Naman Jain <na...@gmail.com> wrote:

> I have a solr core which has a mix of child-free and with-child documents,
> sample xml:
> <add>
> <doc>
> <field name="id">4</field>
> <field name="title">Regular Shirt</field>
> <field name="doc_type">Parent</field>
> <field name="color">Black</field>
> </doc>
> <doc>
> <field name="id">8</field>
> <field name="title">Solid Rug</field>
> <field name="doc_type">Parent</field>
> <field name="pattern">Solid</field>
> </doc>
> <doc>
> <field name="id">1</field>
> <field name="title">Regular color Shirts</field>
> <field name="doc_type">Parent</field>
> <field name="items">
> <doc>
> <field name="id">2</field>
> <field name="doc_type">Child</field>
> <field name="pcs_color">Red</field>>
> </doc>
> <doc>
> <field name="id">3</field>
> <field name="doc_type">Child</field>
> <field name="color">Blue</field>>
> </doc>
> </field>
> </doc>
> <doc>
> <field name="id">5</field>
> <field name="title">Rugs</field>
> <field name="doc_type">Parent</field>
> <field name="items">
> <doc>
> <field name="id">6</field>
> <field name="doc_type">Child</field>
> <field name="pattern">Abstract</field>
> </doc>
> <doc>
> <field name="id">7</field>
> <field name="doc_type">Child</field>
> <field name="pattern">Printed</field>
> </doc>
> </field>
> </doc>
> </add>
> Now i want to write a query which fetched all items [with child and
> without child] with color:red, title having shirt
> Here is my query:
>
> /solr/test/select?q={!parent%20which=doc_type:Parent%20score=max}%20%20{!boost%20b=100.0%20}pcs_color:Red%20{!dismax%20qf=title%20v=%27Regular%27%20score=total}&fl=id,product_class_type,title,score,pcs_color&wt=json
> <http://localhost:8983/solr/test/select?q=%7B!parent%20which=doc_type:Parent%20score=max%7D%20%20%7B!boost%20b=100.0%20%7Dpcs_color:Red%20%7B!dismax%20qf=title%20v=%27Regular%27%20score=total%7D&fl=id,product_class_type,title,score,pcs_color&wt=json>
>
> Error:
> "msg": "Child query must not match same docs with parent filter. Combine
> them as must clauses (+) to find a problem doc. docId=4, class
> org.apache.lucene.search.DisjunctionSumScorer",
> I think docId 4 is matching with query but as this is a parent solr is
> throwing error.
>
> How to proceed here?
>
>
>
>