[英]How to index MongoDB multivalued field into Solr 5.3.0
I have mongodb documents like this,, 我有像这样的mongodb文件,
{
"_id" : ObjectId("5993d55cebb06d20f08521ad"),
"LoginInfoId" : NumberInt(410),
"EstablishmentName" : "xyz",
"ShopCategory" : "Crockery",
"likes" : NumberInt(21),
"ShopCats" : [ 1,5,3 ]
}
{
"_id" : ObjectId("5993d55cebb06d20f088871ad"),
"LoginInfoId" : NumberInt(411),
"EstablishmentName" : "abc",
"ShopCategory" : "Crockery",
"likes" : NumberInt(51),
"ShopCats" : [ 1,8,9 ]
}
I need to index the field ShopCats
into a solr field as comma separated value like this, 我需要将字段
ShopCats
索引为solr字段,像这样用逗号分隔,
"ShopCats" : [ 1,2,3 ]
“ ShopCats”:[1,2,3]
I need to use these values to do filterquery in solr search 我需要使用这些值在solr搜索中执行filterquery
I have tried with some schema field definitions 我尝试了一些架构字段定义
<field name="ShopCats" type="commaDelimited" indexed="true" stored="true" multiValued="true" />
<fieldType name="commaDelimited" class="solr.TextField">
<analyzer>
<tokenizer class="solr.PatternTokenizerFactory" pattern=",\s*" />
</analyzer>
</fieldType>
Still the MongoDb document field ShopCats
is not indexing into solr
. MongoDb文档字段
ShopCats
仍然没有索引到solr
。
I assume that you use a Mongo connector, if yes then Mongo connectors unwinds Arrays so the below 我假设您使用的是Mongo连接器,如果是,则Mongo连接器会展开数组,因此以下内容
{
"_id" : ObjectId("5993d55cebb06d20f08521ad"),
"LoginInfoId" : NumberInt(410),
"EstablishmentName" : "xyz",
"ShopCategory" : "Crockery",
"likes" : NumberInt(21),
"ShopCats" : [ 1,5,3 ]
}
Will be changed to below before indexing 索引编制前将更改为以下内容
{
"_id" : ObjectId("5993d55cebb06d20f08521ad"),
"LoginInfoId" : NumberInt(410),
"EstablishmentName" : "xyz",
"ShopCategory" : "Crockery",
"likes" : NumberInt(21),
"ShopCats.0" : 1,
"ShopCats.1" : 5,
"ShopCats.2" : 3
}
This will happen whenever there is a sub document, and Solr doesn't have he "sub-document" support/ You might be able to get around this with the copyField directive in your schema.xml. 只要有子文档,而Solr没有“子文档”支持,就会发生这种情况。您可能可以在schema.xml中使用copyField指令解决此问题。
I hope this helps. 我希望这有帮助。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.