我如何在Solr schema.xml中表示子文档?

问题描述 投票:0回答:1

我正在尝试实现这样的文档层次结构,其中父级是'Bundle',子级是'Products':

Bundle:
   id
   imageUrl
   Products:
         [
          id:2
          type:"t-shirt"
          sizes:[S,M,L]
          colors:[blue],

          id:3
          type:"hoodie"
          sizes:[M]
          colors:[red]
         ]

这样我就可以支持诸如“ M blue products where imageUrl = xyz”的查询。

我已经这样配置了Managed-schema.xml:

<field name="_root_" type="string" docValues="false" indexed="true" stored="false"/>
<field name="image_url" type="text_en" uninvertible="false" indexed="false" stored="true"/>
<field name="id" type="string" multiValued="false" required="true" stored="true"/>

<fieldType name="_nest_path_" class="solr.NestPathField"/>
<field name="_product_" type="_nest_path_">   
    <field name="id" type="string" multiValued="false" required="true" stored="true"/>
    <field name="type" type="string" indexed="true" stored="true"/>
    <field name="colors" type="strings" multiValued="true" indexed="true" stored="true"/>
    <field name="sizes" type="strings" multiValued="true" ndexed="true" stored="true"/>
</field>    

而且我正在像这样用Java为文档编制索引:

SolrInputDocument parent = new SolrInputDocument();
parent.addField("id", bundle.id);
parent.addField("imageUrl", bundle.imageUrl);
for (Product product : bundle.products) {
   SolrInputDocument child = new SolrInputDocument();
   child.addField("type", product.type);
   child.addField("colors", product.colors);
   parent.addChildDocument(child);
}

但是当我尝试建立索引时,我收到的是“ org.apache.solr.common.SolrException:错误:[doc = 347]非多值字段颜色遇到多个值:[黑色,深皇家,海军] “。

我是否正确构造了我的子女文件?

search solr nested-documents solr-search
1个回答
0
投票

首先,您在尺寸字段上有错误。在那里,您编写了ndexed而不是索引。难道是您用于存储颜色的fieldType“字符串”没有在架构文件中声明为multivalue-field?

© www.soinside.com 2019 - 2024. All rights reserved.