Search 如何在Solr schema.xml中表示子文档?
我试图实现这样的文档层次结构,其中父级是“Bundle”,子级是“Products”:Search 如何在Solr schema.xml中表示子文档?,search,solr,nested-documents,solr-search,Search,Solr,Nested Documents,Solr Search,我试图实现这样的文档层次结构,其中父级是“Bundle”,子级是“Products”: Bundle: id imageUrl Products: [ id:2 type:"t-shirt" sizes:[S,M,L] colors:[blue], id:3 type:"hoodie" sizes:[M]
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>
但当我尝试索引时,我收到“org.apache.solr.common.SolrException:ERROR:[doc=347]非多值字段颜色遇到多个值:[黑色, 深皇家, 海军]”
我是否正确地组织了孩子们的文档 首先,大小字段有一个错误。在这里,您编写了NDEX而不是索引。您用于存储颜色的字段类型“strings”是否在模式文件中未声明为多值字段 我对你的模式有个问题。您给出的示例是完整的模式还是它的一部分?实际上只是模式的Doc fields部分。@P_equals_NP_2021您也可以显示您的db-data-config.xml文件吗?
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);
}