1

Using Solr:5.5.3, Java 7.

I have to fetch all Item:Cap and Size_s:XL, With facets: COLOR_s and SIZE_s. Here Item is part of Parent Doc and Size is part of Child doc. I have thought of using BlockJoin but i am not able to understand how to Query both parent and child at the same time.

Would appreciate any help and guidance. Thanks.

<add>
  <doc>
    <field name="id">1</field>
    <field name="type_s">forSaleItem</field>
    <field name="item">Shirt</field>
    <doc>
      <field name="id">11</field>
      <field name="type_s">itemAttrDoc</field>
      <field name="COLOR_s">Red</field>
      <field name="SIZE_s">XL</field>
      <field name="PRICE_i">6</field>
    </doc>
    <doc>
      <field name="type_s">itemAttrDoc</field>
      <field name="id">12</field>
      <field name="COLOR_s">Red</field>
      <field name="SIZE_s">XL</field>
      <field name="PRICE_i">7</field>
    </doc>
    <doc>
      <field name="type_s">itemAttrDoc</field>
      <field name="id">13</field>
      <field name="COLOR_s">Blue</field>
      <field name="SIZE_s">L</field>
      <field name="PRICE_i">5</field>
    </doc>
  </doc>
  <doc>
    <field name="id">2</field>
    <field name="type_s">forSaleItem</field>
    <field name="item">Cap</field>
    <doc>
      <field name="type_s">itemAttrDoc</field>
      <field name="id">21</field>
      <field name="COLOR_s">Blue</field>
      <field name="SIZE_s">XL</field>
      <field name="PRICE_i">6</field>
    </doc>
    <doc>
      <field name="type_s">itemAttrDoc</field>
      <field name="id">22</field>
      <field name="COLOR_s">Blue</field>
      <field name="SIZE_s">XL</field>
      <field name="PRICE_i">7</field>
    </doc>
    <doc>
      <field name="type_s">itemAttrDoc</field>
      <field name="id">23</field>
      <field name="COLOR_s">Red</field>
      <field name="SIZE_s">L</field>
      <field name="PRICE_i">5</field>
    </doc>
  </doc>
  <doc>
    <field name="id">3</field>
    <field name="type_s">NotforSaleItem</field>
    <field name="item">trouser</field>
    <doc>
      <field name="type_s">itemAttrDoc</field>
      <field name="id">21</field>
      <field name="COLOR_s">Blue</field>
      <field name="SIZE_s">XL</field>
      <field name="PRICE_i">6</field>
    </doc>
    <doc>
      <field name="type_s">itemAttrDoc</field>
      <field name="id">22</field>
      <field name="COLOR_s">Blue</field>
      <field name="SIZE_s">XL</field>
      <field name="PRICE_i">7</field>
    </doc>
    <doc>
      <field name="type_s">itemAttrDoc</field>
      <field name="id">23</field>
      <field name="COLOR_s">Red</field>
      <field name="SIZE_s">L</field>
      <field name="PRICE_i">5</field>
    </doc>
  </doc>
</add>

Edit: type_s identifies the docs, So any query should also contain this field.

A Baldino
  • 178
  • 1
  • 11
  • You'll probably find the answer to your question in the [Solr Block Join Parser Documentation](https://cwiki.apache.org/confluence/display/solr/Other+Parsers#OtherParsers-BlockJoinQueryParsers) – marius_neo Nov 04 '16 at 12:00

1 Answers1

1

Try the following query:

q={!parent which="Item:Cap"}Size_s:XL&facet.field=SIZE_s&facet.field=COLOR_s&facet=on

This should give you the documents that you need.

I've used Solr Block Join Parser Documentation and yonik's Solr Nested Objects Tutorial for reference.

marius_neo
  • 1,535
  • 1
  • 13
  • 28
  • 1
    Thanks a lot for your response. Believe it or not i have written exact query that you provided and i am referring to same link references. Now, i have to query the parent doc by item and also **type_s**, apologise for not mentioning it in my question, this is what i am trying to address now. I might have more fields of parent **and** child docs i need to match with. As i see, i can repeat the query you mentioned. Trying it. http://stackoverflow.com/questions/35003195/solr-block-join-parent-query-with-many-children-constraints – A Baldino Nov 04 '16 at 12:44