如何在 Solr schema.xml 中表示子文档? [英] How do I represent a Child Document in my Solr schema.xml?

查看:195
本文介绍了如何在 Solr schema.xml 中表示子文档?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试实现这样的文档层次结构,其中父级是捆绑包",子级是产品":

I'm trying to achieve a document hierarchy like so, where the parent is the 'Bundle' and the children are '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"之类的查询.

So that I can support queries like "M blue products where imageUrl=xyz".

我已经像这样配置了我的 managed-schema.xml:

I've configured my managed-schema.xml like so:

<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 索引文档,如下所示:

And I'm indexing the document in Java like so:

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: ERROR: [doc=347] 非多值字段颜色遇到多个值:[Black, Deep Royal, Navy]".

But when I try to index, I'm receiving "org.apache.solr.common.SolrException: ERROR: [doc=347] multiple values encountered for non multiValued field colors: [Black,​ Deep Royal,​ Navy]".

我是否正确构建了我的孩子文档?

Did I structure my children documents correctly?

推荐答案

首先,您在尺寸字段中出现错误.在那里你写了索引而不是索引.可能是,用于存储颜色的 fieldType字符串"未在架构文件中声明为多值字段吗?

First of all you have an error at the sizes field. There you wrote ndexed instead of indexed. Could it be, that the fieldType "strings" your using to store the colors is not declared as multivalue-field in the schema-file?

这篇关于如何在 Solr schema.xml 中表示子文档?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆