Reputation: 613
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.
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?
Upvotes: 4
Views: 3584
Reputation: 613
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
Upvotes: 3