4

I'm finding good examples for using JSON in writing to solr with block joins (nested fields basically), but what would the schema.xml look like?

For example, I have a document that has many SKUs and I want to have tags on these skus. There are multiple bits of information with these tags (description, user, type) and they are multivalued since a SKU can have multiple tags.

  • SKU1
    • TagName1, UserId1, Type1
    • TagName2, UserId1, Type1
    • TagName3, UserId2, Type1
    • TagName4, UserId1, Type2
  • SKU2
    • TagName1, UserId1, Type1
    • TagName2, UserId1, Type1
    • TagName3, UserId2, Type1
  • SKU3
    • TagName4, UserId3, Type1

How would the solr schema.xml look with an example like this?

I am using Solr 4.10 - would this be solved if we upgrade to 5.0?

Eldorian
  • 603
  • 1
  • 6
  • 18

1 Answers1

3

I think I figured it out.

Schema would look like this:

<fields>
    <field name="_root_" type="string" indexed="true" stored="false"/>
    <field name="type" type="string" indexed="true" stored="true" />
    <field name="Id" type="text_general" indexed="true" stored="true" required="true" />
    <field name="StockNumber" type="text_general" indexed="true" stored="true" /> 
    <field name="TagName" type="text_general" indexed="true" stored="true" /> 
    <field name="TagUser" type="text_general" indexed="true" stored="true" /> 
    <field name="TagType" type="tint" indexed="true" stored="true" />
<fields>

And to write to it, it would look like this:

<add>
    <doc>
          <field name="Id">SkuTest111</field>
          <field name="type">SKU</field>
          <field name="StockNum">Test111</field>
              <doc>
                  <field name="Id">TagTest111cat</field>
                  <field name="type">Tag</field>
                  <field name="TagName">Cat</field>
                  <field name="TagUser">Eldorian</field>
                  <field name="TagType">1</field>
                  <field name="StockNum">Test111</field>
              </doc>
              <doc>
                  <field name="Id">TagTest111dog</field>
                  <field name="type">Tag</field>
                  <field name="TagName">Dog</field>
                  <field name="TagUser">Eldorian</field>
                  <field name="TagType">2</field>
                  <field name="StockNum">Test111</field>
              </doc>
    </doc>
</add>

In this example you would have a SKU of Test111 with 2 tags, cat and dog.

This appears to only be visible if you do an expanded query which the example of this would be by using this URL on your solr admin:

http://localhost:8983/solr/collection1/select?q={!parent which='type:SKU'}&fq=StockNum:Test111&wt=xml&indent=true&expand=true&expand.field=StockNum&expand.q=StockNum:Test111

Eldorian
  • 603
  • 1
  • 6
  • 18