【发布时间】:2020-03-18 22:49:53
【问题描述】:
我正在尝试实现这样的文档层次结构,其中父级是“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: ERROR: [doc=347] 遇到非多值字段颜色的多个值:[Black, Deep Royal, Navy ]"。
我的孩子文档结构是否正确?
【问题讨论】:
-
我对您的架构有疑问。你给出的那个例子是你的完整模式还是只是其中的一部分?
-
实际上只是模式的 Doc 字段段。
-
@P_equals_NP_2021 你也能显示你的 db-data-config.xml 文件吗?
标签: search solr nested-documents solr-search